From 07ab116456823b92e9c8963eaca5a6ae648390ec Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 24 Mar 2014 21:05:26 +0100 Subject: Moved message stuff into own file --- messages.go | 33 +++++++++++++++++++++++++++++++++ rooms.go | 28 ---------------------------- 2 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 messages.go diff --git a/messages.go b/messages.go new file mode 100644 index 0000000..44e5662 --- /dev/null +++ b/messages.go @@ -0,0 +1,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"` +} diff --git a/rooms.go b/rooms.go index 4aa8542..6a5accd 100644 --- a/rooms.go +++ b/rooms.go @@ -1,37 +1,9 @@ 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"` -} - type Room struct { Messages chan Message Buddies map[string]Buddy -- cgit v1.2.3-70-g09d2