diff options
| author | Kevin Chabowski <kevin@kch42.de> | 2014-03-24 21:05:26 +0100 | 
|---|---|---|
| committer | Kevin Chabowski <kevin@kch42.de> | 2014-03-24 21:05:26 +0100 | 
| commit | 07ab116456823b92e9c8963eaca5a6ae648390ec (patch) | |
| tree | d1b9fb7f3afad6ac2f14b98e388adca30df14f18 | |
| parent | ef1ba61ca79e8348d782a3298fcbd97a0bdb7dc5 (diff) | |
| download | simplechat-07ab116456823b92e9c8963eaca5a6ae648390ec.tar.gz simplechat-07ab116456823b92e9c8963eaca5a6ae648390ec.tar.bz2 simplechat-07ab116456823b92e9c8963eaca5a6ae648390ec.zip | |
Moved message stuff into own file
| -rw-r--r-- | messages.go | 33 | ||||
| -rw-r--r-- | rooms.go | 28 | 
2 files changed, 33 insertions, 28 deletions
| 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"` +} @@ -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 | 
