This commit is contained in:
crusader 2018-09-17 15:29:47 +09:00
parent b02776ec03
commit f6eb351409

View File

@ -5,37 +5,37 @@ import (
"encoding/json" "encoding/json"
) )
type DiscoveryModeEnum int type DiscoveryModeType int
const ( const (
DiscoveryModeEnumPrivileged DiscoveryModeEnum = iota + 1 DiscoveryModeTypePrivileged DiscoveryModeType = iota + 1
DiscoveryModeEnumUnprivileged DiscoveryModeTypeUnprivileged
) )
var ( var (
discoveryModeEnumID = map[DiscoveryModeEnum]string{ discoveryModeTypeID = map[DiscoveryModeType]string{
DiscoveryModeEnumPrivileged: "Privileged", DiscoveryModeTypePrivileged: "Privileged",
DiscoveryModeEnumUnprivileged: "Unprivileged", DiscoveryModeTypeUnprivileged: "Unprivileged",
} }
discoveryModeEnumName = map[string]DiscoveryModeEnum{ discoveryModeTypeName = map[string]DiscoveryModeType{
"Privileged": DiscoveryModeEnumPrivileged, "Privileged": DiscoveryModeTypePrivileged,
"Unprivileged": DiscoveryModeEnumUnprivileged, "Unprivileged": DiscoveryModeTypeUnprivileged,
} }
) )
func (e DiscoveryModeEnum) String() string { func (e DiscoveryModeType) String() string {
return discoveryModeEnumID[e] return discoveryModeTypeID[e]
} }
func (e *DiscoveryModeEnum) MarshalJSON() ([]byte, error) { func (e *DiscoveryModeType) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`) buffer := bytes.NewBufferString(`"`)
buffer.WriteString(discoveryModeEnumID[*e]) buffer.WriteString(discoveryModeTypeID[*e])
buffer.WriteString(`"`) buffer.WriteString(`"`)
return buffer.Bytes(), nil return buffer.Bytes(), nil
} }
func (e *DiscoveryModeEnum) UnmarshalJSON(b []byte) error { func (e *DiscoveryModeType) UnmarshalJSON(b []byte) error {
// unmarshal as string // unmarshal as string
var s string var s string
err := json.Unmarshal(b, &s) err := json.Unmarshal(b, &s)
@ -43,6 +43,6 @@ func (e *DiscoveryModeEnum) UnmarshalJSON(b []byte) error {
return err return err
} }
// lookup value // lookup value
*e = discoveryModeEnumName[s] *e = discoveryModeTypeName[s]
return nil return nil
} }