diff --git a/README.md b/README.md index 381cff8..fa042b0 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,9 @@ build_tags: "" # Whether to prohibit automatic operation disable_run: false +# use GOGC on build +build_go_gc: false + # log level, support debug, info, warn, error, fatal log_level: "debug" ``` diff --git a/README_ZH_CN.md b/README_ZH_CN.md index 250e82f..46e24ea 100644 --- a/README_ZH_CN.md +++ b/README_ZH_CN.md @@ -94,6 +94,12 @@ build_tags: "" # 是否禁止自动运行 disable_run: false +# 编译时使用GOGC,false强制不使用,true根据环境变量配置来,默认使用 +build_go_gc: false + +# 日志级别, 支持 debug, info, warn, error, fatal +log_level: "debug" + ``` ## 微信公众号 diff --git a/config.go b/config.go index 45083dc..2c4c628 100644 --- a/config.go +++ b/config.go @@ -25,6 +25,8 @@ type config struct { CmdArgs []string `yaml:"cmd_args"` // Additional parameters during build BuildArgs []string `yaml:"build_args"` + // use GOGC on build + BuildGOGC bool `yaml:"build_go_gc"` // Environment variables added when running the application Envs []string `yaml:"envs"` // Specify whether the files in the vendor directory are also watched diff --git a/gowatch.go b/gowatch.go index 4c6589c..f4d03a3 100644 --- a/gowatch.go +++ b/gowatch.go @@ -152,7 +152,12 @@ func Autobuild(files []string) { args = append(args, files...) bcmd := exec.Command(cmdName, args...) - bcmd.Env = append(os.Environ(), "GOGC=off") + bcmd.Env = os.Environ() + if !cfg.BuildGOGC { + bcmd.Env = append(bcmd.Env, "GOGC=off") + } else { + bcmd.Env = append(bcmd.Env, "GOGC=on") + } bcmd.Stdout = os.Stdout bcmd.Stderr = os.Stderr log.Infof("Build Args: %s %s", cmdName, strings.Join(args, " ")) diff --git a/main.go b/main.go index da1abb0..7f92ba1 100644 --- a/main.go +++ b/main.go @@ -96,6 +96,9 @@ build_tags: "" # Whether to prohibit automatic operation disable_run: false +# use GOGC on build +build_go_gc: false + # log level, support debug, info, warn, error, fatal log_level: "debug" `