package discovery import ( "bytes" "encoding/json" ) type DiscoveryModeType int const ( DiscoveryModeTypePrivileged DiscoveryModeType = iota + 1 DiscoveryModeTypeUnprivileged ) var ( discoveryModeTypeID = map[DiscoveryModeType]string{ DiscoveryModeTypePrivileged: "Privileged", DiscoveryModeTypeUnprivileged: "Unprivileged", } discoveryModeTypeName = map[string]DiscoveryModeType{ "Privileged": DiscoveryModeTypePrivileged, "Unprivileged": DiscoveryModeTypeUnprivileged, } ) func (e DiscoveryModeType) String() string { return discoveryModeTypeID[e] } func (e *DiscoveryModeType) MarshalJSON() ([]byte, error) { buffer := bytes.NewBufferString(`"`) buffer.WriteString(discoveryModeTypeID[*e]) buffer.WriteString(`"`) return buffer.Bytes(), nil } func (e *DiscoveryModeType) UnmarshalJSON(b []byte) error { // unmarshal as string var s string err := json.Unmarshal(b, &s) if err != nil { return err } // lookup value *e = discoveryModeTypeName[s] return nil }