/
types.go
56 lines (50 loc) · 1.52 KB
/
types.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
package filtering
import (
expr "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
"google.golang.org/protobuf/reflect/protoreflect"
)
// Primitive types.
//
//nolint:gochecknoglobals
var (
TypeInt = &expr.Type{TypeKind: &expr.Type_Primitive{Primitive: expr.Type_INT64}}
TypeFloat = &expr.Type{TypeKind: &expr.Type_Primitive{Primitive: expr.Type_DOUBLE}}
TypeString = &expr.Type{TypeKind: &expr.Type_Primitive{Primitive: expr.Type_STRING}}
TypeBool = &expr.Type{TypeKind: &expr.Type_Primitive{Primitive: expr.Type_BOOL}}
)
// TypeMap returns the type for a map with the provided key and value types.
func TypeMap(keyType, valueType *expr.Type) *expr.Type {
return &expr.Type{
TypeKind: &expr.Type_MapType_{
MapType: &expr.Type_MapType{
KeyType: keyType,
ValueType: valueType,
},
},
}
}
// TypeList returns the type for a list with the provided element type.
func TypeList(elementType *expr.Type) *expr.Type {
return &expr.Type{
TypeKind: &expr.Type_ListType_{
ListType: &expr.Type_ListType{
ElemType: elementType,
},
},
}
}
// TypeEnum returns the type of a protobuf enum.
func TypeEnum(enumType protoreflect.EnumType) *expr.Type {
return &expr.Type{
TypeKind: &expr.Type_MessageType{
MessageType: string(enumType.Descriptor().FullName()),
},
}
}
// Well-known types.
//
//nolint:gochecknoglobals
var (
TypeDuration = &expr.Type{TypeKind: &expr.Type_WellKnown{WellKnown: expr.Type_DURATION}}
TypeTimestamp = &expr.Type{TypeKind: &expr.Type_WellKnown{WellKnown: expr.Type_TIMESTAMP}}
)