func ProcessJSONMessage(msg map[string]interface{}, routingKey string) ([]map[string]interface{}, error) { msg["type"] = fixupMessageType(routingKey) fixupMessage(routingKey, msg) msgs := make([]map[string]interface{}, 0, 1) // explode watchlist/feed hit messages that include a "docs" array if val, ok := msg["docs"]; ok { subdocs := deepcopy.Iface(val).([]interface{}) delete(msg, "docs") for _, submsg := range subdocs { submsg := submsg.(map[string]interface{}) newMsg := deepcopy.Iface(msg).(map[string]interface{}) newSlice := make([]map[string]interface{}, 0, 1) newDoc := deepcopy.Iface(submsg).(map[string]interface{}) fixupMessage(routingKey, newDoc) newSlice = append(newSlice, newDoc) newMsg["docs"] = newSlice msgs = append(msgs, newMsg) } } else { msgs = append(msgs, msg) } return msgs, nil }
func ProcessJSONMessage(msg map[string]interface{}, routingKey string) ([]map[string]interface{}, error) { msg["type"] = routingKey fixupMessage(msg) msgs := make([]map[string]interface{}, 0, 1) // explode watchlist hit messages if strings.HasPrefix(routingKey, "watchlist.hit.") || strings.HasPrefix(routingKey, "watchlist.storage.hit.") { if val, ok := msg["docs"]; ok { subdocs := deepcopy.Iface(val).([]interface{}) delete(msg, "docs") for _, submsg := range subdocs { submsg := submsg.(map[string]interface{}) newMsg := deepcopy.Iface(msg).(map[string]interface{}) newSlice := make([]map[string]interface{}, 0, 1) newDoc := deepcopy.Iface(submsg).(map[string]interface{}) fixupMessage(newDoc) newSlice = append(newSlice, newDoc) newMsg["docs"] = newSlice msgs = append(msgs, newMsg) } } else { // TODO: error condition: "docs" doesn't exist } } else { msgs = append(msgs, msg) } return msgs, nil }