blob: f03eae00749aa2b0fe6566af85b015a1644e2d47 (
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
34
35
|
package chat
import (
"encoding/json"
"errors"
)
// MsgType describes the purpose of a message
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")
}
// Message represents a message that can be sent to a buddy. The Text field has no meaning, if Type != MsgChat.
type Message struct {
Type MsgType `json:"type"`
User string `json:"user"`
Text string `json:"text,omitempty"`
}
|