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