diff --git a/client.go b/client.go index f9f7956..cc179c8 100644 --- a/client.go +++ b/client.go @@ -52,7 +52,7 @@ func NewClient(hostname string, conn net.Conn) *Client { // Client processor blockingly reads everything remote client sends, // splits messages by CRLF and send them to Daemon gorouting for processing // it futher. Also it can signalize that client is unavailable (disconnected). -func (client *Client) Processor(sink chan ClientEvent) { +func (client *Client) Processor(sink chan<- ClientEvent) { var buf_net []byte buf := make([]byte, 0) log.Println("New client", client) diff --git a/daemon.go b/daemon.go index a5b2d77..be9a84e 100644 --- a/daemon.go +++ b/daemon.go @@ -46,11 +46,11 @@ type Daemon struct { rooms map[string]*Room room_sinks map[*Room]chan ClientEvent last_aliveness_check time.Time - log_sink chan LogEvent - state_sink chan StateEvent + log_sink chan<- LogEvent + state_sink chan<- StateEvent } -func NewDaemon(hostname, motd string, log_sink chan LogEvent, state_sink chan StateEvent) *Daemon { +func NewDaemon(hostname, motd string, log_sink chan<- LogEvent, state_sink chan<- StateEvent) *Daemon { daemon := Daemon{hostname: hostname, motd: motd} daemon.clients = make(map[*Client]bool) daemon.rooms = make(map[string]*Room) @@ -195,7 +195,7 @@ func (daemon *Daemon) ClientRegister(client *Client, command string, cols []stri // Register new room in Daemon. Create an object, events sink, save pointers // to corresponding daemon's places and start room's processor goroutine. -func (daemon *Daemon) RoomRegister(name string) (*Room, chan ClientEvent) { +func (daemon *Daemon) RoomRegister(name string) (*Room, chan<- ClientEvent) { room_new := NewRoom(daemon.hostname, name, daemon.log_sink, daemon.state_sink) room_sink := make(chan ClientEvent) daemon.rooms[name] = room_new @@ -252,7 +252,7 @@ func (daemon *Daemon) HandlerJoin(client *Client, cmd string) { } } -func (daemon *Daemon) Processor(events chan ClientEvent) { +func (daemon *Daemon) Processor(events <-chan ClientEvent) { for event := range events { // Check for clients aliveness diff --git a/events.go b/events.go index 6fdf1e7..95760e8 100644 --- a/events.go +++ b/events.go @@ -60,7 +60,7 @@ type LogEvent struct { // Logging events logger itself // Each room's events are written to separate file in logdir // Events include messages, topic and keys changes, joining and leaving -func Logger(logdir string, events chan LogEvent) { +func Logger(logdir string, events <-chan LogEvent) { mode := os.O_CREATE | os.O_WRONLY | os.O_APPEND perm := os.FileMode(0660) var format string @@ -93,7 +93,7 @@ type StateEvent struct { // Room state events saver // Room states shows that either topic or key has been changed // Each room's state is written to separate file in statedir -func StateKeeper(statedir string, events chan StateEvent) { +func StateKeeper(statedir string, events <-chan StateEvent) { mode := os.O_CREATE | os.O_TRUNC | os.O_WRONLY perm := os.FileMode(0660) for event := range events { diff --git a/goircd.go b/goircd.go index 3d69545..aeca83a 100644 --- a/goircd.go +++ b/goircd.go @@ -50,8 +50,7 @@ func Run() { if *logdir == "" { // Dummy logger go func() { - for { - <-log_sink + for _ = range log_sink { } }() } else { @@ -68,8 +67,7 @@ func Run() { if *statedir == "" { // Dummy statekeeper go func() { - for { - <-state_sink + for _ = range state_sink { } }() } else { diff --git a/room.go b/room.go index 87b35f6..08eb46d 100644 --- a/room.go +++ b/room.go @@ -41,11 +41,11 @@ type Room struct { key string members map[*Client]bool hostname string - log_sink chan LogEvent - state_sink chan StateEvent + log_sink chan<- LogEvent + state_sink chan<- StateEvent } -func NewRoom(hostname, name string, log_sink chan LogEvent, state_sink chan StateEvent) *Room { +func NewRoom(hostname, name string, log_sink chan<- LogEvent, state_sink chan<- StateEvent) *Room { room := Room{name: name} room.members = make(map[*Client]bool) room.topic = "" @@ -78,7 +78,7 @@ func (room *Room) StateSave() { room.state_sink <- StateEvent{room.name, room.topic, room.key} } -func (room *Room) Processor(events chan ClientEvent) { +func (room *Room) Processor(events <-chan ClientEvent) { var client *Client for event := range events { client = event.client