-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
config.go
66 lines (60 loc) · 1.9 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)
}