예제 #1
0
func parse(expression string, result *match) (matcher, error) {
	p, err := predicate.NewParser(predicate.Def{
		Functions: map[string]interface{}{
			"Host":       hostTrieMatcher,
			"HostRegexp": hostRegexpMatcher,

			"Path":       pathTrieMatcher,
			"PathRegexp": pathRegexpMatcher,

			"Method":       methodTrieMatcher,
			"MethodRegexp": methodRegexpMatcher,

			"Header":       headerTrieMatcher,
			"HeaderRegexp": headerRegexpMatcher,
		},
		Operators: predicate.Operators{
			AND: newAndMatcher,
		},
	})
	if err != nil {
		return nil, err
	}
	out, err := p.Parse(expression)
	if err != nil {
		return nil, err
	}
	m, ok := out.(matcher)
	if !ok {
		return nil, fmt.Errorf("unknown result type: %T", out)
	}
	m.setMatch(result)
	return m, nil
}
예제 #2
0
파일: parse.go 프로젝트: GitHub9527/vulcan
// Parses expression in the go language into Failover predicates
func ParseExpression(in string) (Predicate, error) {
	p, err := predicate.NewParser(predicate.Def{
		Operators: predicate.Operators{
			AND: AND,
			OR:  OR,
			EQ:  EQ,
			NEQ: NEQ,
			LT:  LT,
			LE:  LE,
			GT:  GT,
			GE:  GE,
		},
		Functions: map[string]interface{}{
			"RequestMethod":  RequestMethod,
			"IsNetworkError": IsNetworkError,
			"Attempts":       Attempts,
			"ResponseCode":   ResponseCode,
		},
	})
	if err != nil {
		return nil, err
	}
	out, err := p.Parse(convertLegacy(in))
	if err != nil {
		return nil, err
	}
	pr, ok := out.(Predicate)
	if !ok {
		return nil, fmt.Errorf("expected predicate, got %T", out)
	}
	return pr, nil
}
예제 #3
0
// ParseExpression parses expression in the go language into predicates.
func ParseExpression(in string) (threshold.Predicate, error) {
	p, err := predicate.NewParser(predicate.Def{
		Operators: predicate.Operators{
			AND: threshold.AND,
			OR:  threshold.OR,
			EQ:  threshold.EQ,
			NEQ: threshold.NEQ,
			LT:  threshold.LT,
			LE:  threshold.LE,
			GT:  threshold.GT,
			GE:  threshold.GE,
		},
		Functions: map[string]interface{}{
			"LatencyAtQuantileMS": latencyAtQuantile,
			"NetworkErrorRatio":   networkErrorRatio,
			"ResponseCodeRatio":   responseCodeRatio,
		},
	})
	if err != nil {
		return nil, err
	}
	out, err := p.Parse(in)
	if err != nil {
		return nil, err
	}
	pr, ok := out.(threshold.Predicate)
	if !ok {
		return nil, fmt.Errorf("expected predicate, got %T", out)
	}
	return pr, nil
}
예제 #4
0
// parseExpression parses expression in the go language into predicates.
func parseExpression(in string) (hpredicate, error) {
	p, err := predicate.NewParser(predicate.Def{
		Operators: predicate.Operators{
			AND: and,
			OR:  or,
			EQ:  eq,
			NEQ: neq,
			LT:  lt,
			LE:  le,
			GT:  gt,
			GE:  ge,
		},
		Functions: map[string]interface{}{
			"LatencyAtQuantileMS": latencyAtQuantile,
			"NetworkErrorRatio":   networkErrorRatio,
			"ResponseCodeRatio":   responseCodeRatio,
		},
	})
	if err != nil {
		return nil, err
	}
	out, err := p.Parse(in)
	if err != nil {
		return nil, err
	}
	pr, ok := out.(hpredicate)
	if !ok {
		return nil, fmt.Errorf("expected predicate, got %T", out)
	}
	return pr, nil
}
예제 #5
0
파일: threshold.go 프로젝트: 2722/lantern
// Parses expression in the go language into Failover predicates
func parseExpression(in string) (hpredicate, error) {
	p, err := predicate.NewParser(predicate.Def{
		Operators: predicate.Operators{
			AND: and,
			OR:  or,
			EQ:  eq,
			NEQ: neq,
			LT:  lt,
			GT:  gt,
			LE:  le,
			GE:  ge,
		},
		Functions: map[string]interface{}{
			"RequestMethod":  requestMethod,
			"IsNetworkError": isNetworkError,
			"Attempts":       attempts,
			"ResponseCode":   responseCode,
		},
	})
	if err != nil {
		return nil, err
	}
	out, err := p.Parse(in)
	if err != nil {
		return nil, err
	}
	pr, ok := out.(hpredicate)
	if !ok {
		return nil, fmt.Errorf("expected predicate, got %T", out)
	}
	return pr, nil
}