1 Star 0 Fork 3

zsly科技有限公司/gohangout-plus-bak

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config_parser.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
childe 提交于 2020-05-22 15:30 . remove debug info
package main
import (
"errors"
"regexp"
"strings"
"github.com/golang/glog"
yaml "gopkg.in/yaml.v2"
)
type Config map[string]interface{}
type Parser interface {
parse(filename string) (map[string]interface{}, error)
}
func parseConfig(filename string) (map[string]interface{}, error) {
lowerFilename := strings.ToLower(filename)
if strings.HasSuffix(lowerFilename, ".yaml") || strings.HasSuffix(lowerFilename, ".yml") {
yp := &YamlParser{}
return yp.parse(filename)
}
return nil, errors.New("unknown config format. config filename should ends with yaml|yml")
}
// remove sensitive info before output
func removeSensitiveInfo(config map[string]interface{}) string {
re := regexp.MustCompile(`(.*password:\s+)(.*)`)
re2 := regexp.MustCompile(`(http(s)?://\w+:)\w+`)
b, err := yaml.Marshal(config)
if err != nil {
glog.Errorf("marshal config error: %s", err)
return ""
}
output := make([]string, 0, 0)
for _, l := range strings.Split(string(b), "\n") {
if re.MatchString(l) {
output = append(output, re.ReplaceAllString(l, "${1}xxxxxx"))
continue
}
if re2.MatchString(l) {
output = append(output, re2.ReplaceAllString(l, "${1}xxxxxx"))
continue
}
output = append(output, l)
}
return strings.Join(output, "\n")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zsleyou/gohangout-plus-bak.git
git@gitee.com:zsleyou/gohangout-plus-bak.git
zsleyou
gohangout-plus-bak
gohangout-plus-bak
master

搜索帮助