forked from External/ergo
initial commit
This commit is contained in:
commit
a427e2bb47
6 changed files with 175 additions and 0 deletions
43
src/irc/protocol.go
Normal file
43
src/irc/protocol.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package irc
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
line string
|
||||
client *Client
|
||||
}
|
||||
|
||||
func (m *Message) Encode() string {
|
||||
return m.line
|
||||
}
|
||||
|
||||
|
||||
// Adapt `chan string` to a `chan Message`.
|
||||
func NewMessageChan(strch chan string) chan Message {
|
||||
msgch := make(chan Message)
|
||||
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
<- done
|
||||
close(msgch)
|
||||
}()
|
||||
|
||||
// str -> msg
|
||||
go func() {
|
||||
for str := range strch {
|
||||
msgch <- Message{str, nil}
|
||||
}
|
||||
done <- true
|
||||
}()
|
||||
|
||||
// msg -> str
|
||||
go func() {
|
||||
for message := range msgch {
|
||||
strch <- message.Encode()
|
||||
}
|
||||
done <- true
|
||||
}()
|
||||
|
||||
return msgch
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue