Browse Source

Merge pull request #466 from WangLeonard/fix-system-config

修复在线修改系统配置的bug
main
奇淼(piexlmax 3 years ago
committed by GitHub
parent
commit
f7ffbf2d4c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      server/core/viper.go
  2. 6
      server/utils/fmt_plus.go

1
server/core/viper.go

@ -36,6 +36,7 @@ func Viper(path ...string) *viper.Viper {
v := viper.New()
v.SetConfigFile(config)
v.SetConfigType("yaml")
err := v.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))

6
server/utils/fmt_plus.go

@ -18,7 +18,11 @@ func StructToMap(obj interface{}) map[string]interface{} {
var data = make(map[string]interface{})
for i := 0; i < obj1.NumField(); i++ {
data[obj1.Field(i).Name] = obj2.Field(i).Interface()
if obj1.Field(i).Tag.Get("mapstructure") != "" {
data[obj1.Field(i).Tag.Get("mapstructure")] = obj2.Field(i).Interface()
} else {
data[obj1.Field(i).Name] = obj2.Field(i).Interface()
}
}
return data
}

Loading…
Cancel
Save