-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomaintype.go
47 lines (38 loc) · 906 Bytes
/
domaintype.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
package api
import (
"encoding/json"
)
//go:generate stringer -type=DomainType -linecomment
type DomainType int
const (
_ DomainType = iota
DomainTypeCloudflare // cloudflare
DomainTypeHostname // hostname
DomainTypeWildcard // wildcard
)
var validDomainType = map[DomainType]bool{
DomainTypeCloudflare: true,
DomainTypeHostname: true,
DomainTypeWildcard: true,
}
func (t DomainType) MarshalJSON() ([]byte, error) {
return json.Marshal(t.String())
}
func (t *DomainType) UnmarshalJSON(b []byte) error {
var s string
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*t = DomainType(0)
for _, x := range []DomainType{DomainTypeCloudflare, DomainTypeHostname, DomainTypeWildcard} {
if x.String() == s {
*t = x
return nil
}
}
return nil
}
func (t DomainType) Valid() bool {
return validDomainType[t]
}