forked from neophenix/protoc-gen-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wkt.go
81 lines (73 loc) · 1.77 KB
/
wkt.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
package plugin
import (
"strings"
)
// all WKTs come from the google proto package
const wktBasePath = ".google.protobuf."
const (
message = 1
enum = 2
)
// not sure what else to store as a val, so use something simple
var wktLookup = map[string]int8{
"Any": message,
"Api": message,
"BoolValue": message,
"BytesValue": message,
"DoubleValue": message,
"Duration": message,
"Empty": message,
"Enum": message,
"EnumValue": message,
"Field": message,
"Field.Cardinality": enum,
"Field.Kind": enum,
"FieldMask": message,
"FloatValue": message,
"Int32Value": message,
"Int64Value": message,
"ListValue": message,
"Method": message,
"Mixin": message,
"NullValue": enum,
"Option": message,
"SourceContext": message,
"StringValue": message,
"Struct": message,
"Syntax": enum,
"Timestamp": message,
"Type": message,
"UInt32Value": message,
"UInt64Value": message,
"Value": message,
}
func isWKT(typeName string) bool {
if strings.Contains(typeName, wktBasePath) {
typeName = strings.ReplaceAll(typeName, wktBasePath, "")
if _, ok := wktLookup[typeName]; ok {
return true
}
}
return false
}
func isWKTString(typeName string) bool {
if typeName == wktBasePath+"StringValue" {
return true
}
return false
}
func isWKTInt(typeName string) bool {
if strings.Contains(typeName, "Int") {
return true
}
return false
}
func isWKTFloat(typeName string) bool {
if typeName == wktBasePath+"DoubleValue" {
return true
}
if typeName == wktBasePath+"FloatValue" {
return true
}
return false
}