package overflow_subscriber import ( "encoding/json" "fmt" ) type SubscribeMessage struct { TargetType SubscribeTargetType `json:"targetType"` Targets []string `json:"targets"` MessageRaw *json.RawMessage `json:"message"` Message []byte } type SubscribeMessageBody struct { Version string `json:"jsonrpc"` Method string `json:"method"` Params interface{} `json:"params,omitempty"` } type SubscribeTargetType int const ( MEMBER_SESSION SubscribeTargetType = iota MEMBER_ID PROBE_ID ) var ( subscribeTargetTypeID = map[SubscribeTargetType]string{ MEMBER_SESSION: "MEMBER_SESSION", MEMBER_ID: "MEMBER_ID", PROBE_ID: "PROBE_ID", } subscribeTargetTypeName = map[string]SubscribeTargetType{ "MEMBER_SESSION": MEMBER_SESSION, "MEMBER_ID": MEMBER_ID, "PROBE_ID": PROBE_ID, } ) func (st SubscribeTargetType) String() string { return subscribeTargetTypeID[st] } func (st *SubscribeTargetType) MarshalJSON() ([]byte, error) { value, ok := subscribeTargetTypeID[*st] if !ok { return nil, fmt.Errorf("Invalid EnumType[%s] value", *st) } return json.Marshal(value) } func (st *SubscribeTargetType) UnmarshalJSON(b []byte) error { // unmarshal as string var s string err := json.Unmarshal(b, &s) if err != nil { return err } value, ok := subscribeTargetTypeName[s] if !ok { return fmt.Errorf("Invalid EnumType[%s] value", s) } *st = value return nil }