添加env环境变量展示

This commit is contained in:
bjdgyc
2021-07-29 17:04:02 +08:00
parent d78deafc0c
commit c943b9ee9b
3 changed files with 38 additions and 25 deletions

View File

@@ -5,8 +5,6 @@ import (
"os"
"path/filepath"
"reflect"
"github.com/spf13/viper"
)
const (
@@ -31,7 +29,7 @@ var (
type ServerConfig struct {
// LinkAddr string `json:"link_addr"`
ConfFile string `json:"conf_file"`
Conf string `json:"conf"`
ServerAddr string `json:"server_addr"`
ServerDTLSAddr string `json:"server_dtls_addr"`
ServerDTLS bool `json:"server_dtls"`
@@ -83,6 +81,10 @@ func initServerCfg() {
// Cfg.FilesPath = getAbsPath(base, Cfg.FilesPath)
// Cfg.LogPath = getAbsPath(base, Cfg.LogPath)
if Cfg.AdminPass == defaultPwd {
fmt.Fprintln(os.Stderr, "=== 使用默认的admin_pass有安全风险请设置新的admin_pass ===")
}
if Cfg.JwtSecret == defaultJwt {
fmt.Fprintln(os.Stderr, "=== 使用默认的jwt_secret有安全风险请设置新的jwt_secret ===")
}
@@ -116,19 +118,18 @@ func initCfg() {
for _, v := range configs {
if v.Name == tag {
if v.Typ == cfgStr {
value.SetString(viper.GetString(v.Name))
value.SetString(linkViper.GetString(v.Name))
}
if v.Typ == cfgInt {
value.SetInt(int64(viper.GetInt(v.Name)))
value.SetInt(int64(linkViper.GetInt(v.Name)))
}
if v.Typ == cfgBool {
value.SetBool(viper.GetBool(v.Name))
value.SetBool(linkViper.GetBool(v.Name))
}
}
}
}
Cfg.ConfFile = cfgFile
initServerCfg()
}
@@ -152,9 +153,6 @@ func ServerCfg2Slice() []SCfg {
value := s.Field(i)
tag := field.Tag.Get("json")
usage, env := getUsageEnv(tag)
// if usage == "" {
// continue
// }
datas = append(datas, SCfg{Name: tag, Env: env, Info: usage, Data: value.Interface()})
}