blob: 44e566277dff46d8fc1b287d24b6d0b2bcf31c96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package main
import (
"encoding/json"
"errors"
)
type MsgType int
const (
MsgChat MsgType = iota // Default
MsgJoin
MsgLeave
)
func (mt *MsgType) MarshalJSON() ([]byte, error) {
switch *mt {
case MsgChat:
return json.Marshal("chat")
case MsgJoin:
return json.Marshal("join")
case MsgLeave:
return json.Marshal("leave")
}
return nil, errors.New("Unknown message type")
}
type Message struct {
Type MsgType `json:"type"`
User string `json:"user"`
Text string `json:"text,omitempty"`
}
|