fix(config): check value by zero for init default

This commit is contained in:
Denis Gukov 2023-09-15 01:57:25 +02:00
parent f553def7f2
commit 175d629518

View File

@ -189,9 +189,9 @@ func (conf *ConfigType) ToJSON() ([]byte, error) {
// ConfigInit reads in cli flags, and switches actions appropriately on them
func ConfigInit(configPath string) {
fmt.Println("Loading config")
loadConfigDefaults()
loadConfigFile(configPath)
loadConfigEnvironment()
loadConfigDefaults()
fmt.Println("Validating config")
validateConfig()
@ -256,14 +256,14 @@ func loadDefaultsToObject(obj interface{}) error {
v = reflect.Indirect(v)
}
if v.Type().Kind() != reflect.Struct {
return nil
}
for i := 0; i < t.NumField(); i++ {
fieldType := t.Field(i)
fieldValue := v.Field(i)
if !fieldValue.IsZero() {
continue
}
if fieldType.Type.Kind() == reflect.Struct {
err := loadDefaultsToObject(fieldValue.Addr())
if err != nil {