原逻辑中需要完善处:关于配置文件后缀检测处的补充
源代码如下:
if len(envSuffix) > 0 {
filepath := ".env." + envSuffix
if _, err := os.Stat(filepath); err == nil {
// 如 .env.testing 或 .env.stage
envPath = filepath
}
}
建议如下:
if len(envSuffix) > 0 {
filepath := ".env." + envSuffix
if _, err := os.Stat(filepath); err == nil {
// 如 .env.testing 或 .env.stage
envPath = filepath
} else {
panic(err)
}
}
原来的逻辑容易出现配置不存在问题:
比如编译后:./tmp/gohub –env=test 时,当.env.test不存在时,不会报异常,会默认取.env内的配置项。