Set property K for int type + write config to disk
This commit is contained in:
140
cmd/utils.go
140
cmd/utils.go
@ -206,116 +206,44 @@ func getStructFieldValue(parentStruct interface{}, fieldName string) (*reflect.V
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(fieldName, ".") {
|
||||
|
||||
// Le code degueulasse mais qui marche
|
||||
legacy := false
|
||||
|
||||
if legacy {
|
||||
fs := strings.Split(fieldName, ".")
|
||||
fmt.Printf("Dealing with field \"%s\" of struct \"%s\"\n", strings.Join(fs[1:], "."), fs[0])
|
||||
var f reflect.Value
|
||||
var found bool
|
||||
for i := 0 ; i < v.NumField() ; i++ {
|
||||
if typeOfV.Field(i).Name == fs[0] {
|
||||
f = v.Field(i)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return &v, fieldName, errors.New(fmt.Sprintf("Field not found: %s", fieldName))
|
||||
}
|
||||
|
||||
for ; f.Kind() == reflect.Ptr ; {
|
||||
fmt.Printf("We got a pointer as a nested field, get Elem form it\n")
|
||||
f = f.Elem()
|
||||
}
|
||||
|
||||
fmt.Printf("v.kind() = %v\n", v.Kind().String())
|
||||
fmt.Printf("v = %v\n", v)
|
||||
fmt.Printf("f.kind() = %v\n", f.Kind().String())
|
||||
fmt.Printf("f = %v\n", f)
|
||||
/*if f.Kind() == reflect.Ptr {
|
||||
fmt.Printf("We got a pointer as a nested field, get Elem form it\n")
|
||||
f = f.Elem()
|
||||
}*/
|
||||
//f := v.Elem().FieldByName(fs[0])
|
||||
if f.Kind() == reflect.Struct {
|
||||
//return getStructFieldValue(&f, strings.Join(fs[1:], "."))
|
||||
//return getStructFieldValue(f, strings.Join(fs[1:], "."))
|
||||
|
||||
|
||||
/* GRUIIIK */
|
||||
|
||||
g := f.FieldByName(fs[1])
|
||||
fmt.Printf("get substruct field, f.kind() = %v\n", f.Kind().String())
|
||||
fmt.Printf("get substruct field, g.kind() = %v\n", g.Kind().String())
|
||||
fmt.Printf("get substruct field, f = %v\n", f)
|
||||
fmt.Printf("get substruct field, g = %v\n", g)
|
||||
if g.IsValid() {
|
||||
fmt.Printf("Return g = %v of Kind %s\n", g, g.Kind().String())
|
||||
return &g, fieldName, nil
|
||||
} else {
|
||||
return &f, fieldName, errors.New(fmt.Sprintf("Field not found: %s", fieldName))
|
||||
}
|
||||
|
||||
/* FIN DE GRUIIIIK */
|
||||
} else {
|
||||
log.Fatalln(fmt.Sprintf("%s is not a struct: %s\n", fs[0], f.Kind().String()))
|
||||
}
|
||||
} else {
|
||||
var f reflect.Value
|
||||
var found bool
|
||||
fs := strings.Split(fieldName, ".")
|
||||
// Loop through properties
|
||||
for i, curF := range fs {
|
||||
found = false
|
||||
for j := 0 ; j < v.NumField() ; j++ {
|
||||
if typeOfV.Field(j).Name == curF {
|
||||
f = v.Field(j)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return &v, fieldName, errors.New(fmt.Sprintf("Field not found: %s", fieldName))
|
||||
}
|
||||
|
||||
for ; f.Kind() == reflect.Ptr ; f = f.Elem() {}
|
||||
|
||||
/*fmt.Printf("v.kind() = %v\n", v.Kind().String())
|
||||
fmt.Printf("v = %v\n", v)
|
||||
fmt.Printf("f.kind() = %v\n", f.Kind().String())
|
||||
fmt.Printf("f = %v\n", f)*/
|
||||
|
||||
// If this is the last loop, return result even if it's a struct
|
||||
// FIXME : What if we got interface?
|
||||
if f.Kind() != reflect.Struct && i < len(fs)-1 {
|
||||
if f.IsValid() {
|
||||
//fmt.Printf("Return f = %v of Kind %s\n", f, f.Kind().String())
|
||||
return &f, fieldName, nil
|
||||
} else {
|
||||
return &v, fieldName, errors.New(fmt.Sprintf("Field not found: %s", fieldName))
|
||||
}
|
||||
} else {
|
||||
v = f
|
||||
typeOfV = v.Type()
|
||||
}
|
||||
var f reflect.Value
|
||||
var found bool
|
||||
|
||||
fs := strings.Split(fieldName, ".")
|
||||
// Loop through properties
|
||||
for i, curF := range fs {
|
||||
found = false
|
||||
for j := 0 ; j < v.NumField() ; j++ {
|
||||
if typeOfV.Field(j).Name == curF {
|
||||
f = v.Field(j)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
f := v.FieldByName(fieldName)
|
||||
fmt.Printf("No substruct, v.kind() = %v\n", v.Kind().String())
|
||||
fmt.Printf("No substruct, f.kind() = %v\n", f.Kind().String())
|
||||
fmt.Printf("No substruct, v = %v\n", v)
|
||||
fmt.Printf("No substruct, f = %v\n", f)
|
||||
if f.IsValid() {
|
||||
fmt.Printf("Return f = %v of Kind %s\n", f, f.Kind().String())
|
||||
return &f, fieldName, nil
|
||||
} else {
|
||||
if !found {
|
||||
return &v, fieldName, errors.New(fmt.Sprintf("Field not found: %s", fieldName))
|
||||
}
|
||||
|
||||
for ; f.Kind() == reflect.Ptr ; f = f.Elem() {}
|
||||
|
||||
/*fmt.Printf("v.kind() = %v\n", v.Kind().String())
|
||||
fmt.Printf("v = %v\n", v)
|
||||
fmt.Printf("f.kind() = %v\n", f.Kind().String())
|
||||
fmt.Printf("f = %v\n", f)*/
|
||||
|
||||
// If this is the last loop, return result even if it's a struct
|
||||
// FIXME : What if we got interface?
|
||||
if f.Kind() != reflect.Struct && i < len(fs)-1 {
|
||||
if f.IsValid() {
|
||||
//fmt.Printf("Return f = %v of Kind %s\n", f, f.Kind().String())
|
||||
return &f, fieldName, nil
|
||||
} else {
|
||||
return &v, fieldName, errors.New(fmt.Sprintf("Field not found: %s", fieldName))
|
||||
}
|
||||
} else {
|
||||
v = f
|
||||
typeOfV = v.Type()
|
||||
}
|
||||
}
|
||||
|
||||
return &v, fieldName, nil
|
||||
|
Reference in New Issue
Block a user