golint: eventsHandler -> EventsHandler.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2015-04-15 14:21:05 -07:00
parent 16cd6cc2d8
commit f5979b2fed
3 changed files with 11 additions and 10 deletions

View File

@ -28,7 +28,7 @@ const APIVERSION = "1.16"
type context struct { type context struct {
cluster cluster.Cluster cluster cluster.Cluster
eventsHandler *eventsHandler eventsHandler *EventsHandler
debug bool debug bool
tlsConfig *tls.Config tlsConfig *tls.Config
} }

View File

@ -9,23 +9,24 @@ import (
"github.com/docker/swarm/cluster" "github.com/docker/swarm/cluster"
) )
type eventsHandler struct { // EventsHandler broadcasts events to multiple client listeners.
type EventsHandler struct {
sync.RWMutex sync.RWMutex
ws map[string]io.Writer ws map[string]io.Writer
cs map[string]chan struct{} cs map[string]chan struct{}
} }
// NewEventsHandler creates a new eventsHandler for a cluster. // NewEventsHandler creates a new EventsHandler for a cluster.
// The new eventsHandler is initialized with no writers or channels. // The new eventsHandler is initialized with no writers or channels.
func NewEventsHandler() *eventsHandler { func NewEventsHandler() *EventsHandler {
return &eventsHandler{ return &EventsHandler{
ws: make(map[string]io.Writer), ws: make(map[string]io.Writer),
cs: make(map[string]chan struct{}), cs: make(map[string]chan struct{}),
} }
} }
// Add adds the writer and a new channel for the remote address. // Add adds the writer and a new channel for the remote address.
func (eh *eventsHandler) Add(remoteAddr string, w io.Writer) { func (eh *EventsHandler) Add(remoteAddr string, w io.Writer) {
eh.Lock() eh.Lock()
eh.ws[remoteAddr] = w eh.ws[remoteAddr] = w
eh.cs[remoteAddr] = make(chan struct{}) eh.cs[remoteAddr] = make(chan struct{})
@ -33,13 +34,13 @@ func (eh *eventsHandler) Add(remoteAddr string, w io.Writer) {
} }
// Wait waits on a signal from the remote address. // Wait waits on a signal from the remote address.
func (eh *eventsHandler) Wait(remoteAddr string) { func (eh *EventsHandler) Wait(remoteAddr string) {
<-eh.cs[remoteAddr] <-eh.cs[remoteAddr]
} }
// Handle writes information about a cluster event to each remote address in the cluster that has been added to the events handler. // Handle writes information about a cluster event to each remote address in the cluster that has been added to the events handler.
// After a successful write to a remote address, the associated channel is closed and the address is removed from the events handler. // After a successful write to a remote address, the associated channel is closed and the address is removed from the events handler.
func (eh *eventsHandler) Handle(e *cluster.Event) error { func (eh *EventsHandler) Handle(e *cluster.Event) error {
eh.RLock() eh.RLock()
str := fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%d,%q:{%q:%q,%q:%q,%q:%q,%q:%q}}", str := fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%d,%q:{%q:%q,%q:%q,%q:%q,%q:%q}}",
@ -71,7 +72,7 @@ func (eh *eventsHandler) Handle(e *cluster.Event) error {
} }
// Size returns the number of remote addresses that the events handler currently contains. // Size returns the number of remote addresses that the events handler currently contains.
func (eh *eventsHandler) Size() int { func (eh *EventsHandler) Size() int {
eh.RLock() eh.RLock()
defer eh.RUnlock() defer eh.RUnlock()
return len(eh.ws) return len(eh.ws)

View File

@ -35,7 +35,7 @@ func newListener(proto, addr string, tlsConfig *tls.Config) (net.Listener, error
// //
// The expected format for a host string is [protocol://]address. The protocol // The expected format for a host string is [protocol://]address. The protocol
// must be either "tcp" or "unix", with "tcp" used by default if not specified. // must be either "tcp" or "unix", with "tcp" used by default if not specified.
func ListenAndServe(c cluster.Cluster, hosts []string, enableCors bool, tlsConfig *tls.Config, eventsHandler *eventsHandler) error { func ListenAndServe(c cluster.Cluster, hosts []string, enableCors bool, tlsConfig *tls.Config, eventsHandler *EventsHandler) error {
context := &context{ context := &context{
cluster: c, cluster: c,
eventsHandler: eventsHandler, eventsHandler: eventsHandler,