1 Star 0 Fork 21

yuexudong / go-admin-core

forked from go-admin-team / go-admin-core 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
preprocessor.go 416 Bytes
一键复制 编辑 原始数据 按行查看 历史
lwnmengjing 提交于 2020-12-08 15:18 . 借鉴go-micro的config模块
package reader
import (
"os"
"regexp"
)
func ReplaceEnvVars(raw []byte) ([]byte, error) {
re := regexp.MustCompile(`\$\{([A-Za-z0-9_]+)\}`)
if re.Match(raw) {
dataS := string(raw)
res := re.ReplaceAllStringFunc(dataS, replaceEnvVars)
return []byte(res), nil
} else {
return raw, nil
}
}
func replaceEnvVars(element string) string {
v := element[2 : len(element)-1]
el := os.Getenv(v)
return el
}
Go
1
https://gitee.com/yuexudong/go-admin-core.git
git@gitee.com:yuexudong/go-admin-core.git
yuexudong
go-admin-core
go-admin-core
v1.4.4

搜索帮助