diff options
author | Kevin Chabowski <kevin@kch42.de> | 2014-03-25 15:54:32 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2014-03-25 15:54:32 +0100 |
commit | 966c17bb84866f10fc9e995df4107ed11ed2bdce (patch) | |
tree | 5e0446c4bb80dcefd7e705ce8de38d1a06989418 /buddy.go | |
parent | 3aa1c450a3376a4339354579f90b6111b963c78a (diff) | |
download | simplechat-966c17bb84866f10fc9e995df4107ed11ed2bdce.tar.gz simplechat-966c17bb84866f10fc9e995df4107ed11ed2bdce.tar.bz2 simplechat-966c17bb84866f10fc9e995df4107ed11ed2bdce.zip |
Move protocol agnostic stuff into own package.
So we can test it more easily.
Diffstat (limited to 'buddy.go')
-rw-r--r-- | buddy.go | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/buddy.go b/buddy.go deleted file mode 100644 index 1128956..0000000 --- a/buddy.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "time" -) - -type Buddy struct { - Nick string - Receive chan Message - room *Room -} - -func NewBuddy(nick string, room *Room) *Buddy { - return &Buddy{ - Nick: nick, - Receive: make(chan Message), - room: room, - } -} - -func (b *Buddy) Leave() { - b.room.Leave(b.Nick) -} - -func (b *Buddy) Push(msg Message) { - go func() { - select { - case b.Receive <- msg: - case <-time.Tick(time.Millisecond * 100): - } - }() -} - -// Say sends a text as a chat message of this user to the connected room. -func (b *Buddy) Say(text string) { - b.room.Messages <- Message{ - Type: MsgChat, - User: b.Nick, - Text: text, - } -} |