/
field.go
94 lines (72 loc) · 2.46 KB
/
field.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package atc
import (
"fmt"
"strings"
)
// This file defines the field types, field transforms, and field constants used in Kong's expression router.
// https://docs.konghq.com/gateway/latest/reference/router-expressions-language/ is the upstream reference that
// describes these fields.
// TransformLower instructs Kong to transform a field (for example, http.path) to lowercase before comparing it to
// a value in a predicate expression. It can only be applied to the left side of a predicate expression.
type TransformLower struct {
inner LHS
}
func (t TransformLower) FieldType() FieldType {
return FieldTypeString
}
func (t TransformLower) String() string {
return fmt.Sprintf("lower(%s)", t.inner.String())
}
func NewTransformerLower(inner LHS) TransformLower {
return TransformLower{inner: inner}
}
// StringField is defined for fields with constant name and having string type.
// The inner string value is the name of the field.
type StringField string
func (f StringField) FieldType() FieldType {
return FieldTypeString
}
func (f StringField) String() string {
return string(f)
}
// https://docs.konghq.com/gateway/latest/reference/router-expressions-language/#available-fields
const (
FieldNetProtocol StringField = "net.protocol"
FieldTLSSNI StringField = "tls.sni"
FieldHTTPMethod StringField = "http.method"
FieldHTTPHost StringField = "http.host"
FieldHTTPPath StringField = "http.path"
)
// IntField is defined for fields with constant name and having integer type.
// The inner string value is the name of the field.
type IntField string
func (f IntField) FieldType() FieldType {
return FieldTypeInt
}
func (f IntField) String() string {
return string(f)
}
// https://docs.konghq.com/gateway/latest/reference/router-expressions-language/#available-fields
const (
FieldNetDstPort IntField = "net.dst.port"
)
// HTTPHeaderField extracts the value of an HTTP header from the request.
type HTTPHeaderField struct {
HeaderName string
}
func (f HTTPHeaderField) FieldType() FieldType {
return FieldTypeString
}
func (f HTTPHeaderField) String() string {
return "http.headers." + strings.ToLower(strings.ReplaceAll(f.HeaderName, "-", "_"))
}
// HTTPQueryField extracts the value of an HTTP query parameter from the query string of the request.
type HTTPQueryField struct {
QueryParamName string
}
func (f HTTPQueryField) FieldType() FieldType {
return FieldTypeString
}
func (f HTTPQueryField) String() string {
return "http.queries." + f.QueryParamName
}