package health import ( "encoding/json" "fmt" ) type SocketErrorEnum int const ( SocketErrorEnumUNKNOWN SocketErrorEnum = iota + 1 SocketErrorEnumHOSTUNREACH SocketErrorEnumCONNREFUSED ) var ( socketErrorEnumID = map[SocketErrorEnum]string{ SocketErrorEnumUNKNOWN: "UNKNOWN", SocketErrorEnumHOSTUNREACH: "HOSTUNREACH", SocketErrorEnumCONNREFUSED: "CONNREFUSED", } socketErrorEnumKey = map[string]SocketErrorEnum{ "UNKNOWN": SocketErrorEnumUNKNOWN, "HOSTUNREACH": SocketErrorEnumHOSTUNREACH, "CONNREFUSED": SocketErrorEnumCONNREFUSED, } ) func (e SocketErrorEnum) String() string { return socketErrorEnumID[e] } func (e SocketErrorEnum) MarshalJSON() ([]byte, error) { value, ok := socketErrorEnumID[e] if !ok { return nil, fmt.Errorf("Invalid EnumType[%s] value", e) } return json.Marshal(value) } func (e SocketErrorEnum) UnmarshalJSON(b []byte) error { var s string err := json.Unmarshal(b, &s) if err != nil { return err } value, ok := socketErrorEnumKey[s] if !ok { return fmt.Errorf("Invalid EnumType[%s] value", s) } e = value return nil }