/
primitive.go
93 lines (88 loc) · 1.23 KB
/
primitive.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
package ir
import "fmt"
type PrimitiveType int
func (p PrimitiveType) String() string {
switch p {
case String:
return "string"
case ByteSlice:
return "[]byte"
case Int:
return "int"
case Int8:
return "int8"
case Int16:
return "int16"
case Int32:
return "int32"
case Int64:
return "int64"
case Uint:
return "uint"
case Uint8:
return "uint8"
case Uint16:
return "uint16"
case Uint32:
return "uint32"
case Uint64:
return "uint64"
case Float32:
return "float32"
case Float64:
return "float64"
case Bool:
return "bool"
case Null:
return "struct{}"
case Time:
return "time.Time"
case Duration:
return "time.Duration"
case UUID:
return "uuid.UUID"
case MAC:
return "net.HardwareAddr"
case IP:
return "netip.Addr"
case URL:
return "url.URL"
case File:
return "ht.MultipartFile"
case Custom:
return "<custom>"
default:
panic(fmt.Sprintf("unexpected PrimitiveType: %d", p))
}
}
// IsString whether this type is string.
func (p PrimitiveType) IsString() bool {
return p == String
}
const (
None PrimitiveType = iota
String
ByteSlice
Int
Int8
Int16
Int32
Int64
Uint
Uint8
Uint16
Uint32
Uint64
Float32
Float64
Bool
Null
Time
Duration
UUID
MAC
IP
URL
File
Custom
)