// match: Match a simple pattern match and return matched value // // given input: // {"score_value":24,"event_click":true} // // match("score_") => {"value":24} // match("amount_") => false // match("event_") => {"click":true} // func Match(ctx expr.EvalContext, items ...value.Value) (value.MapValue, bool) { //u.Debugf("Match(): %T %v", item, item) mv := make(map[string]interface{}) for _, item := range items { switch node := item.(type) { case value.StringValue: matchKey := node.Val() for rowKey, val := range ctx.Row() { if strings.HasPrefix(rowKey, matchKey) && val != nil { newKey := strings.Replace(rowKey, matchKey, "", 1) if newKey != "" { mv[newKey] = val } } } default: u.Warnf("unsuported key type: %T %v", item, item) } } if len(mv) > 0 { //u.Infof("found new: %v", mv) return value.NewMapValue(mv), true } //u.Warnf("could not find key: %T %v", item, item) return value.EmptyMapValue, false }