func getProp(d interface{}, label string) (interface{}, bool) {
switch reflect.TypeOf(d).Kind() {
case reflect.Struct:
v := reflect.ValueOf(d).FieldByName(label)
return v.Interface(), true
}
return nil, false
}
Reference:
https://stackoverflow.com/questions/13856539/how-do-you-get-struct-value-on-unknown-interface
No comments:
Post a Comment