summaryrefslogtreecommitdiff
path: root/chat/messages.go
diff options
context:
space:
mode:
Diffstat (limited to 'chat/messages.go')
-rw-r--r--chat/messages.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/chat/messages.go b/chat/messages.go
new file mode 100644
index 0000000..793fc6c
--- /dev/null
+++ b/chat/messages.go
@@ -0,0 +1,33 @@
+package chat
+
+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"`
+}