主配置文件app.conf 内容如下:
- #默认配置
- runmode = local
-
- [local]
- include "local.conf"
-
- [dev]
- include "dev.conf"
-
- [test]
- include "test.conf"
-
- [prod]
- include "prod.conf"
然后分别建立四个文件:
local.conf(本地运行环境配置):
- appname = ssp_api_go
- httpport = 8080
dev.conf (开发环境配置)
- appname = ssp_api_go
- httpport = 8081
test.conf (测试环境配置)
- appname = ssp_api_go
- httpport = 8082
prod.conf (生产环境配置)
- appname = ssp_api_go
- httpport = 80
修改main.go文件:
- func main() {
- env := beego.AppConfig.String("runmode")
- logs.Info("adapterName:", env)
- configFilePath, err := filepath.Abs("conf/" + env + ".conf")
- if err != nil {
- logs.Error("configFilePathError", err)
- }
- err = beego.LoadAppConfig("ini", configFilePath)
- if err != nil {
- logs.Error("loadConfigFileError", err)
- }
- beego.Run()
- }
通过修改主配置文件:app.conf,里面的runmode 参数来加载不同的配置文件。