protohackers/cmd/budgetchat/user.go

28 lines
370 B
Go

package main
import "net"
type user struct {
conn net.Conn
nick string
online bool
output chan string
}
func newUser(conn net.Conn) *user {
return &user{
conn: conn,
output: make(chan string),
}
}
func (u *user) write(s string) {
u.output <- s + "\n"
}
func (u *user) sendMessage() {
for line := range u.output {
u.conn.Write([]byte(line))
}
}