func generateMatchCondition()

in metric_storeview_routing.go [256:284]


func generateMatchCondition(matchStr string) (*Condition, error) {
	if matchStr == "" {
		return nil, errors.New("empty match string")
	}
	if matchStr == ".*" || matchStr == ".+" {
		return &Condition{MatchAll: true, MatchType: MatchEqual, MatchValue: matchStr}, nil
	}
	if val := strictPrefixRegex(matchStr); val != "" {
		return &Condition{MatchAll: false, MatchType: MatchPrefix, MatchValue: val, MatchFunc: prefixFunc}, nil
	} else if val = strictContainsRegex(matchStr); val != "" {
		return &Condition{MatchAll: false, MatchType: MatchContains, MatchValue: val, MatchFunc: containsFunc}, nil
	} else if val = strictSuffixRegex(matchStr); val != "" {
		return &Condition{MatchAll: false, MatchType: MatchSuffix, MatchValue: val, MatchFunc: suffixFunc}, nil
	} else if includes := checkIncludeCond(matchStr); len(includes) > 0 {
		valuesMap := make(map[string]struct{}, len(includes))
		for _, v := range includes {
			valuesMap[v] = struct{}{}
		}
		return &Condition{MatchAll: false, MatchType: MatchInclude, MatchValue: matchStr, IncludeValuesMap: valuesMap, MatchFunc: includeFunc}, nil
	} else if ok, _ := isSimpleStrRegex(matchStr); ok {
		return &Condition{MatchAll: false, MatchType: MatchEqual, MatchValue: matchStr, MatchFunc: equalFunc}, nil
	} else {
		regex, cErr := regexp.Compile(matchStr)
		if cErr == nil {
			return &Condition{MatchAll: false, MatchType: MatchRegexp, MatchValue: matchStr, RegexPattern: regex, MatchFunc: regexpFunc}, nil
		}
		return nil, cErr
	}
}