-
Notifications
You must be signed in to change notification settings - Fork 106
/
mode.go
45 lines (36 loc) · 903 Bytes
/
mode.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
package inputdockerstats
import "github.com/tsaikd/KDGoLib/enumutil"
// Mode enum for docker stats log mode
type Mode int8
// List all valid enum of Mode
const (
ModeFull Mode = 1 + iota
ModeSimple
)
var factoryMode = enumutil.NewEnumFactory().
Add(ModeFull, "full").
Add(ModeSimple, "simple").
Build()
func (t Mode) String() string {
return factoryMode.String(t)
}
// MarshalJSON return jsonfy []byte of enum
func (t Mode) MarshalJSON() ([]byte, error) {
return factoryMode.MarshalJSON(t)
}
// UnmarshalJSON decode json data to enum
func (t *Mode) UnmarshalJSON(b []byte) (err error) {
return factoryMode.UnmarshalJSON(t, b)
}
// IsMode check string is valid enum
func IsMode(s string) bool {
return factoryMode.IsEnumString(s)
}
// ParseMode string to enum
func ParseMode(s string) Mode {
enum, err := factoryMode.ParseString(s)
if err != nil {
return 0
}
return enum.(Mode)
}