1 Star 2 Fork 0

陈志端 / dubbo-go-starter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
env_util.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
陈志端 提交于 2022-03-01 17:21 . Fixed some bugs
package util
import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
"fmt"
"gitee.com/changeden/dubbo-go-starter/common"
"os"
"strings"
)
func GetEnvAndTrim(key string) string {
return strings.TrimSpace(os.Getenv(key))
}
func PresetEnv() {
common.ConfigPath = GetEnvAndTrim(common.ApplicationConfigFilePathKey) // 通过环境变量获取应用配置文件
common.DubboConfigPath = GetEnvAndTrim(common.DubboConfigFilePathKey) // Dubbo服务配置文件
if common.ConfigPath == "" {
common.ConfigPath = common.DefaultApplicationConfigFilePath // 默认配置文件
}
if common.DubboConfigPath == "" { // 默认配置文件
err := os.Setenv(common.DubboConfigFilePathKey, common.DefaultApplicationConfigFilePath)
if err != nil {
logger.Error(err)
} else {
common.DubboConfigPath = common.DefaultApplicationConfigFilePath
}
}
}
func CheckFile(path string, pathKey string) (file *os.File, err error) {
file, err = os.Open(path)
if err != nil {
logger.Error(err)
err = fmt.Errorf("环境变量[%s]所配置的文件地址[%s]不存在", pathKey, path)
}
return
}
Go
1
https://gitee.com/changeden/dubbo-go-starter.git
git@gitee.com:changeden/dubbo-go-starter.git
changeden
dubbo-go-starter
dubbo-go-starter
v0.1.6

搜索帮助