Vendor main dependencies.
This commit is contained in:
parent
49a09ab7dd
commit
dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions
47
vendor/github.com/vulcand/route/parse.go
generated
vendored
Normal file
47
vendor/github.com/vulcand/route/parse.go
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
package route
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vulcand/predicate"
|
||||
)
|
||||
|
||||
// IsValid checks whether expression is valid
|
||||
func IsValid(expr string) bool {
|
||||
_, err := parse(expr, &match{})
|
||||
return err == nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue