diff --git a/core/router/path.go b/core/router/path.go index 732e944c..914f75e7 100644 --- a/core/router/path.go +++ b/core/router/path.go @@ -209,12 +209,13 @@ func (ps *RoutePathReverser) Path(routeName string, paramValues ...interface{}) return r.ResolvePath(toStringSlice(paramValues)...) } -func toStringSlice(args []interface{}) []string { - var argsString []string - if len(args) > 0 { - argsString = make([]string, len(args), len(args)) +func toStringSlice(args []interface{}) (argsString []string) { + argsSize := len(args) + if argsSize <= 0 { + return } + argsString = make([]string, argsSize, argsSize) for i, v := range args { if s, ok := v.(string); ok { argsString[i] = s @@ -229,7 +230,7 @@ func toStringSlice(args []interface{}) []string { } } } - return argsString + return } // Remove the URL for now, it complicates things for the whole framework without a specific benefits, @@ -246,21 +247,16 @@ func (ps *RoutePathReverser) URL(routeName string, paramValues ...interface{}) ( return } - if len(paramValues) == 0 { - return r.Path - } - - args := toStringSlice(paramValues) - host := ps.vhost scheme := ps.vscheme + args := toStringSlice(paramValues) + // if it's dynamic subdomain then the first argument is the subdomain part // for this part we are responsible not the custom routers - if r.Subdomain == SubdomainWildcardIndicator { + if len(args) > 0 && r.Subdomain == SubdomainWildcardIndicator { subdomain := args[0] host = subdomain + "." + host args = args[1:] // remove the subdomain part for the arguments, - } if parsedPath := r.ResolvePath(args...); parsedPath != "" { diff --git a/view/amber.go b/view/amber.go index 32547830..84d6d97f 100644 --- a/view/amber.go +++ b/view/amber.go @@ -213,7 +213,7 @@ func (s *AmberEngine) ExecuteWriter(w io.Writer, filename string, layout string, } if tmpl := s.fromCache(filename); tmpl != nil { - return tmpl.ExecuteTemplate(w, filename, bindingData) + return tmpl.Execute(w, bindingData) } return fmt.Errorf("Template with name %s doesn't exists in the dir", filename) diff --git a/websocket/connection.go b/websocket/connection.go index 2e6f46cf..9f18dcbd 100644 --- a/websocket/connection.go +++ b/websocket/connection.go @@ -131,6 +131,8 @@ type ( // MessageFunc is the second argument to the Emitter's Emit functions. // A callback which should receives one parameter of type string, int, bool or any valid JSON/Go struct MessageFunc interface{} + // PingFunc is the callback which fires each ping + PingFunc func() // Connection is the front-end API that you will use to communicate with the client side Connection interface { // Emitter implements EmitMessage & Emit @@ -154,6 +156,8 @@ type ( OnDisconnect(DisconnectFunc) // OnError registers a callback which fires when this connection occurs an error OnError(ErrorFunc) + // OnPing registers a callback which fires on each ping + OnPing(PingFunc) // FireStatusCode can be used to send a custom error message to the connection // // It does nothing more than firing the OnError listeners. It doesn't sends anything to the client. @@ -200,6 +204,7 @@ type ( onDisconnectListeners []DisconnectFunc onRoomLeaveListeners []LeaveRoomFunc onErrorListeners []ErrorFunc + onPingListeners []PingFunc onNativeMessageListeners []NativeMessageFunc onEventListeners map[string][]MessageFunc // these were maden for performance only @@ -305,6 +310,8 @@ func (c *connection) startPinger() { // verifies if already disconected break } + //fire all OnPing methods + c.fireOnPing() // try to ping the client, if failed then it disconnects err := c.write(websocket.PingMessage, []byte{}) if err != nil { @@ -430,6 +437,10 @@ func (c *connection) OnError(cb ErrorFunc) { c.onErrorListeners = append(c.onErrorListeners, cb) } +func (c *connection) OnPing(cb PingFunc) { + c.onPingListeners = append(c.onPingListeners, cb) +} + func (c *connection) FireOnError(errorMessage string) { for _, cb := range c.onErrorListeners { cb(errorMessage) @@ -492,6 +503,13 @@ func (c *connection) fireOnLeave(roomName string) { } } +func (c *connection) fireOnPing() { + // fire the onPingListeners + for i := range c.onPingListeners { + c.onPingListeners[i]() + } +} + func (c *connection) Disconnect() error { return c.server.Disconnect(c.ID()) }