-
Notifications
You must be signed in to change notification settings - Fork 11
/
sync_type.go
46 lines (41 loc) · 914 Bytes
/
sync_type.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
package types
import "fmt"
type SyncType string
const (
SyncTypeNormal SyncType = "normal"
SyncTypeClean SyncType = "clean"
SyncTypeCleanAll SyncType = "clean_all"
)
// UnmarshalText
func (s *SyncType) UnmarshalText(text []byte) error {
switch syncType := string(text); syncType {
case "normal":
fallthrough
case "NORMAL":
*s = SyncTypeNormal
case "clean":
fallthrough
case "CLEAN":
*s = SyncTypeClean
case "clean_all":
fallthrough
case "CLEAN_ALL":
*s = SyncTypeCleanAll
default:
return fmt.Errorf("unknown sync_type value %q", syncType)
}
return nil
}
// MarshalText
func (s SyncType) MarshalText() ([]byte, error) {
switch s {
case SyncTypeNormal:
return []byte(SyncTypeNormal), nil
case SyncTypeClean:
return []byte(SyncTypeClean), nil
case SyncTypeCleanAll:
return []byte(SyncTypeCleanAll), nil
default:
return nil, fmt.Errorf("unknown sync_type %s", s)
}
}