-
Notifications
You must be signed in to change notification settings - Fork 0
/
gt.go
101 lines (87 loc) · 2.72 KB
/
gt.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
95
96
97
98
99
100
101
package gt
import (
"database/sql/driver"
"encoding"
"encoding/json"
"fmt"
)
/*
Implemented by all types in this package. Returns the underlying value as
a "primitive" / "well-known" type, such as `int64`, `string`, `time.Time`
depending on the type. All types in this package use `.Get` to implement
`sql.Valuer`.
*/
type Getter interface{ Get() any }
/*
Implemented by all types in this package. Same as `.Scan`, but panics on error.
*/
type Setter interface{ Set(any) }
/*
Implemented by all types in this package, as well as some stdlib types.
Equivalent to `reflect.ValueOf(val).IsZero()`, but also works on pointer
receivers.
*/
type Zeroable interface{ IsZero() bool }
/*
Implemented by all types in this package. For all "null" types, this is
equivalent to `gt.Zeroable`. For all non-"null" types, this always returns
`false`.
TODO consider removing from `Encodable` and from non-nullable types.
*/
type Nullable interface{ IsNull() bool }
/*
Zeroes the receiver. Implemented by all types in this package, as well as some
stdlib types.
*/
type Zeroer interface{ Zero() }
/*
Missing counterpart to `encoding.TextUnmarshaler`. Parses a string, rather than
a byte slice.
*/
type Parser interface{ Parse(string) error }
/*
Implemented by all types in this package, as well as some stdlib types. Appends
the default text representation of the receiver to the provided buffer.
*/
type AppenderTo interface{ AppendTo([]byte) []byte }
/*
Mutable counterpart to `gt.Getter`. Where `.Get` returns an underlying primitive
value as a copy, `.GetPtr` returns an underlying primitive value as a pointer.
Decoding into the underlying value by using `json.Unmarshal`, SQL decoding, or
any other decoding mechanism must mutate the target, and the resulting state
must be valid for that type.
Unlike other interfaces, not every type in this package implements this. This is
implemented only by types whose underlying value is built-in (strings and
numbers) or also supports decoding (`time.Time`).
*/
type PtrGetter interface{ GetPtr() any }
// Copy of `"database/sql".Scanner` to avoid a big import.
type Scanner interface{ Scan(any) error }
/*
Implemented by all types in this package. Various methods for converting the
value to another representation. All methods must be implemented on value
types, rather than pointer types.
*/
type Encodable interface {
Getter
Zeroable
Nullable
fmt.Stringer
encoding.TextMarshaler
json.Marshaler
driver.Valuer
}
/*
Implemented by all types in this package. Various methods for mutating the
underlying value by decoding or zeroing. All methods must be implemented on
pointer types, rather than value types.
*/
type Decodable interface {
Setter
Zeroer
Parser
AppenderTo
encoding.TextUnmarshaler
json.Unmarshaler
Scanner
}