-
Notifications
You must be signed in to change notification settings - Fork 432
/
routes.go
47 lines (41 loc) · 1.16 KB
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package helpers
import (
gatwayv1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1"
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/core/matchers"
)
const (
ExactPath = iota
PrefixPath
RegexPath
)
func MakeMultiMatcherRoute(pathType1, length1, pathType2, length2 int) *v1.Route {
return &v1.Route{Matchers: []*matchers.Matcher{
MakeMatcher(pathType1, length1),
MakeMatcher(pathType2, length2),
}}
}
func MakeRoute(pathType, length int) *v1.Route {
return &v1.Route{Matchers: []*matchers.Matcher{MakeMatcher(pathType, length)}}
}
func MakeGatewayRoute(pathType, length int) *gatwayv1.Route {
return &gatwayv1.Route{Matchers: []*matchers.Matcher{MakeMatcher(pathType, length)}}
}
func MakeMatcher(pathType, length int) *matchers.Matcher {
pathStr := "/"
for i := 0; i < length; i++ {
pathStr += "s/"
}
m := &matchers.Matcher{}
switch pathType {
case ExactPath:
m.PathSpecifier = &matchers.Matcher_Exact{pathStr}
case PrefixPath:
m.PathSpecifier = &matchers.Matcher_Prefix{pathStr}
case RegexPath:
m.PathSpecifier = &matchers.Matcher_Regex{pathStr}
default:
panic("bad test")
}
return m
}