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