3 Star 1 Fork 0

Gitee 极速下载 / gowatch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/silenceper/gowatch
克隆/下载
config.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
zhenlinwen 提交于 2021-12-03 21:12 . add log level support
package main
import (
"io/ioutil"
"os"
"path/filepath"
"gopkg.in/yaml.v1"
)
var configFile = "./gowatch.yml"
type config struct {
// The name of the running app, the default current directory name
AppName string `yaml:"appname"`
// Specify the program path for output execution
Output string `yaml:"output"`
// Need to add watch file suffix name, the default is'.go',
WatchExts []string `yaml:"watch_exts"`
// Need to add watch directory, the default is the current folder
WatchPaths []string `yaml:"watch_paths"`
// Additional commands executed before the build command
PrevBuildCmds []string `yaml:"prev_build_cmds"`
// Extra parameters when running the application
CmdArgs []string `yaml:"cmd_args"`
// Additional parameters during build
BuildArgs []string `yaml:"build_args"`
// Environment variables added when running the application
Envs []string `yaml:"envs"`
// Specify whether the files in the vendor directory are also watched
VendorWatch bool `yaml:"vendor_watch"`
// Specify a directory that does not require watch
ExcludedPaths []string `yaml:"excluded_paths"`
// For packages or files that need to be compiled, use the -p parameter first
BuildPkg string `yaml:"build_pkg"`
// -tags parameter accepted during go build
BuildTags string `yaml:"build_tags"`
// Specify whether the program runs automatically
DisableRun bool `yaml:"disable_run"`
// commands when build finished to run
RunCmd string `yaml:"run_cmd"`
// log level, support: debug, info, warn, error, fatal
LogLevel string `yaml:"log_level"`
}
func parseConfig() *config {
c := &config{}
filename, _ := filepath.Abs(configFile)
if !fileExist(filename) {
return c
}
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
panic(err)
}
return c
}
func fileExist(filename string) bool {
_, err := os.Stat(filename)
return err == nil || os.IsExist(err)
}
1
https://gitee.com/mirrors/gowatch.git
git@gitee.com:mirrors/gowatch.git
mirrors
gowatch
gowatch
master

搜索帮助