forked from thecubed/gogstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MsgType.go
51 lines (39 loc) · 918 Bytes
/
MsgType.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
package inputexec
import (
"database/sql/driver"
"github.com/tsaikd/KDGoLib/enumutil"
)
type MsgType int8
const (
MsgTypeText MsgType = 1 + iota
MsgTypeJson
)
var msgTypeEnum = enumutil.NewEnumFactory().
Add(MsgTypeText, "text").
Add(MsgTypeJson, "json").
Build()
func (t MsgType) String() string {
return msgTypeEnum.String(t)
}
func (t MsgType) MarshalJSON() ([]byte, error) {
return msgTypeEnum.MarshalJSON(t)
}
func (t *MsgType) UnmarshalJSON(b []byte) (err error) {
return msgTypeEnum.UnmarshalJSON(t, b)
}
func (t *MsgType) Scan(value interface{}) (err error) {
return msgTypeEnum.Scan(t, value)
}
func (t MsgType) Value() (v driver.Value, err error) {
return msgTypeEnum.Value(t)
}
func IsMsgType(s string) bool {
return msgTypeEnum.IsEnumString(s)
}
func ParseMsgType(s string) MsgType {
enum, err := msgTypeEnum.ParseString(s)
if err != nil {
return 0
}
return enum.(MsgType)
}