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