From f841bd4157e9607d9bbaafd7d9b2674e465fc7bc Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Tue, 21 Jun 2016 14:18:22 +0300 Subject: [PATCH] https://github.com/kataras/iris/issues/201 --- iris/run.go | 3 ++- websocket/connection.go | 22 +++++++++++----------- websocket/{emmiter.go => emitter.go} | 24 ++++++++++++------------ 3 files changed, 25 insertions(+), 24 deletions(-) rename websocket/{emmiter.go => emitter.go} (53%) diff --git a/iris/run.go b/iris/run.go index 6a043e5b..0d538a20 100644 --- a/iris/run.go +++ b/iris/run.go @@ -111,7 +111,8 @@ func runAndWatch(flags cli.Flags) error { if !isWindows { fname = " " // we don't want to print the ".gooutput..." so dont print anything as a name } - printer.Infof("\n[OP: %d] File '%s' changed, reloading...", atomic.LoadUint32(×), fname) + + printer.Infof("\n[OP: %d] File %s changed, reloading...", atomic.LoadUint32(×), fname) //kill the prev run diff --git a/websocket/connection.go b/websocket/connection.go index 1d8c4c9d..60eb41cf 100644 --- a/websocket/connection.go +++ b/websocket/connection.go @@ -23,8 +23,8 @@ type ( MessageFunc interface{} // Connection is the client Connection interface { - // Emmiter implements EmitMessage & Emit - Emmiter + // Emitter implements EmitMessage & Emit + Emitter // ID returns the connection's identifier ID() string // OnDisconnect registers a callback which fires when this connection is closed by an error or manual @@ -37,7 +37,7 @@ type ( EmitError(errorMessage string) // To defines where server should send a message // returns an emmiter to send messages - To(string) Emmiter + To(string) Emitter // OnMessage registers a callback which fires when native websocket message received OnMessage(NativeMessageFunc) // On registers a callback to a particular event which fires when a message to this event received @@ -57,9 +57,9 @@ type ( onNativeMessageListeners []NativeMessageFunc onEventListeners map[string][]MessageFunc // these were maden for performance only - self Emmiter // pre-defined emmiter than sends message to its self client - broadcast Emmiter // pre-defined emmiter that sends message to all except this - all Emmiter // pre-defined emmiter which sends message to all clients + self Emitter // pre-defined emmiter than sends message to its self client + broadcast Emitter // pre-defined emmiter that sends message to all except this + all Emitter // pre-defined emmiter which sends message to all clients server *server } @@ -81,9 +81,9 @@ func newConnection(websocketConn *websocket.Conn, s *server) *connection { server: s, } - c.self = newEmmiter(c, c.id) - c.broadcast = newEmmiter(c, NotMe) - c.all = newEmmiter(c, All) + c.self = newEmitter(c, c.id) + c.broadcast = newEmitter(c, NotMe) + c.all = newEmitter(c, All) return c } @@ -251,7 +251,7 @@ func (c *connection) EmitError(errorMessage string) { } } -func (c *connection) To(to string) Emmiter { +func (c *connection) To(to string) Emitter { if to == NotMe { // if send to all except me, then return the pre-defined emmiter, and so on return c.broadcast } else if to == All { @@ -260,7 +260,7 @@ func (c *connection) To(to string) Emmiter { return c.self } // is an emmiter to another client/connection - return newEmmiter(c, to) + return newEmitter(c, to) } func (c *connection) EmitMessage(nativeMessage []byte) error { diff --git a/websocket/emmiter.go b/websocket/emitter.go similarity index 53% rename from websocket/emmiter.go rename to websocket/emitter.go index 027a2c37..892cc491 100644 --- a/websocket/emmiter.go +++ b/websocket/emitter.go @@ -1,44 +1,44 @@ package websocket const ( - // All is the string which the Emmiter use to send a message to all + // All is the string which the Emitter use to send a message to all All = "" - // NotMe is the string which the Emmiter use to send a message to all except this connection + // NotMe is the string which the Emitter use to send a message to all except this connection NotMe = ";iris;to;all;except;me;" - // Broadcast is the string which the Emmiter use to send a message to all except this connection, same as 'NotMe' + // Broadcast is the string which the Emitter use to send a message to all except this connection, same as 'NotMe' Broadcast = NotMe ) type ( - // Emmiter is the message/or/event manager - Emmiter interface { + // Emitter is the message/or/event manager + Emitter interface { // EmitMessage sends a native websocket message EmitMessage([]byte) error // Emit sends a message on a particular event Emit(string, interface{}) error } - emmiter struct { + emitter struct { conn *connection to string } ) -var _ Emmiter = &emmiter{} +var _ Emitter = &emitter{} -// emmiter implementation +// emitter implementation -func newEmmiter(c *connection, to string) *emmiter { - return &emmiter{conn: c, to: to} +func newEmitter(c *connection, to string) *emitter { + return &emitter{conn: c, to: to} } -func (e *emmiter) EmitMessage(nativeMessage []byte) error { +func (e *emitter) EmitMessage(nativeMessage []byte) error { mp := messagePayload{e.conn.id, e.to, nativeMessage} e.conn.server.messages <- mp return nil } -func (e *emmiter) Emit(event string, data interface{}) error { +func (e *emitter) Emit(event string, data interface{}) error { message, err := serialize(event, data) if err != nil { return err