properly return multi-value fields in an array
This commit is contained in:
parent
19305c6b5f
commit
eb16b3c563
|
@ -48,7 +48,20 @@ func (dm *DocumentMatch) AddFieldValue(name string, value interface{}) {
|
|||
if dm.Fields == nil {
|
||||
dm.Fields = make(map[string]interface{})
|
||||
}
|
||||
dm.Fields[name] = value
|
||||
existingVal, ok := dm.Fields[name]
|
||||
if ok {
|
||||
valSlice, ok := existingVal.([]interface{})
|
||||
if ok {
|
||||
// already a slice, append to it
|
||||
valSlice = append(valSlice, value)
|
||||
} else {
|
||||
// create a slice
|
||||
valSlice = []interface{}{existingVal, value}
|
||||
}
|
||||
dm.Fields[name] = valSlice
|
||||
} else {
|
||||
dm.Fields[name] = value
|
||||
}
|
||||
}
|
||||
|
||||
type DocumentMatchCollection []*DocumentMatch
|
||||
|
|
Loading…
Reference in New Issue