Commit 76786482 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

MergeStructs: panic when unexpected property kind is found

parent 37960dc6
......@@ -53,7 +53,6 @@ func MergeStructs(responses interface{}, mergedResp interface{}) {
responseValue := responsesValue.Index(index)
for fieldnum := 0; fieldnum < numFields; fieldnum++ {
// field := respType.Field(fieldnum)
fieldVal := responseValue.Field(fieldnum)
// Skip unexported fields.
......@@ -61,7 +60,7 @@ func MergeStructs(responses interface{}, mergedResp interface{}) {
continue
}
// fmt.Printf(" - field %d: %10v ", fieldnum, field.Name)
// fmt.Printf(" - field %d: %10v ", fieldnum, respType.Field(fieldnum).Name)
useValue := false
switch fieldVal.Kind() {
case reflect.Ptr:
......@@ -73,8 +72,11 @@ func MergeStructs(responses interface{}, mergedResp interface{}) {
case reflect.Bool:
useValue = fieldVal.Bool()
// fmt.Printf("is bool : %v", useValue)
case reflect.Int:
useValue = fieldVal.Int() != 0
// fmt.Printf("is int : %v", useValue)
default:
// fmt.Printf("is kind : %v (not using)", fieldVal.Kind())
panic(fmt.Sprintf("field %s is of unmergeable kind %v", respType.Field(fieldnum).Name, fieldVal.Kind()))
}
// fmt.Println()
......@@ -84,7 +86,6 @@ func MergeStructs(responses interface{}, mergedResp interface{}) {
resultField := resultValue.Field(fieldnum)
resultField.Set(fieldVal)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment