Created
May 5, 2015 15:10
-
-
Save andboson/a95308b27840ba84d85c to your computer and use it in GitHub Desktop.
Beego different configs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
............ | |
//another config placed in conf/prod/app.conf | |
func Init() { //old init() | |
//something like init database | |
} | |
func main() { | |
if beego.RunMode == "dev" { | |
beego.DirectoryIndex = true | |
beego.StaticDir["/swagger"] = "swagger" | |
} | |
detectProdConfig() | |
Init() | |
beego.Run() | |
} | |
func detectProdConfig(){ | |
apppath, _ := filepath.Abs(filepath.Dir(beego.AppConfigPath)) | |
appConfigPatgh := apppath + string(filepath.Separator) + "prod" + string(filepath.Separator) + "app.conf" | |
if(fileExists(appConfigPatgh)) { | |
beego.AppConfigPath = appConfigPatgh | |
beego.ParseConfig() | |
} | |
} | |
func fileExists(name string) bool { | |
if _, err := os.Stat(name); err != nil { | |
if os.IsNotExist(err) { | |
return false | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment