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