From 73b8396cd6adee6956d3d1107ec4bc920d83e847 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 27 Jan 2017 14:25:48 +0200 Subject: [PATCH] https://github.com/iris-contrib/plugin/blob/master/cors/plugin.go#L28 --- README.md | 6 ++++-- iris.go | 34 +++++++++++++++++++++++++++++++++- websocket.go | 6 +++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 100e2155..f853c2af 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@

- Logo created by an Iris community member, @coreyworrell - + + Logo created by an Iris community member, @OneebMalik +
diff --git a/iris.go b/iris.go index a402e93a..18358603 100644 --- a/iris.go +++ b/iris.go @@ -176,6 +176,7 @@ type ( UseGlobal(middleware ...Handler) UseGlobalFunc(middleware ...HandlerFunc) + ChangeRouter(http.Handler) Lookup(routeName string) Route Lookups() []Route SetRouteOnline(r Route, HTTPMethod string) bool @@ -1037,6 +1038,38 @@ func (s *Framework) UseGlobalFunc(handlersFn ...HandlerFunc) { s.UseGlobal(convertToHandlers(handlersFn)...) } +// ChangeRouter force-changes the pre-defined iris' router while RUNTIME +// this function can be used to wrap the existing router with other. +// You can already do all these things with plugins, this function is a sugar for the craziest among us. +// +// Example of its only usage: +// https://github.com/iris-contrib/plugin/blob/master/cors/plugin.go#L22 +// https://github.com/iris-contrib/plugin/blob/master/cors/plugin.go#L25 +// https://github.com/iris-contrib/plugin/blob/master/cors/plugin.go#L28 +// +// It's recommended that you use Plugin.PreBuild to change the router BEFORE the BUILD state. +func ChangeRouter(h http.Handler) { + Default.ChangeRouter(h) +} + +// ChangeRouter force-changes the pre-defined iris' router while RUNTIME +// this function can be used to wrap the existing router with other. +// You can already do all these things with plugins, this function is a sugar for the craziest among us. +// +// Example of its only usage: +// https://github.com/iris-contrib/plugin/blob/master/cors/plugin.go#L22 +// https://github.com/iris-contrib/plugin/blob/master/cors/plugin.go#L25 +// https://github.com/iris-contrib/plugin/blob/master/cors/plugin.go#L28 +// +// It's recommended that you use Plugin.PreBuild to change the router BEFORE the BUILD state. +func (s *Framework) ChangeRouter(h http.Handler) { + s.Router = h + s.srv.Handler = h +} + +///TODO: Inside note for author: +// make one and only one common API interface for all iris' supported Routers(gorillamux,httprouter,corsrouter) + // Lookup returns a registered route by its name func Lookup(routeName string) Route { return Default.Lookup(routeName) @@ -1558,7 +1591,6 @@ func (api *muxAPI) Handle(method string, registeredPath string, handlers ...Hand r := api.mux.register(method, subdomain, path, middleware) api.apiRoutes = append(api.apiRoutes, r) - // should we remove the api.apiRoutes on the .Party (new children party) ?, No, because the user maybe use this party later // should we add to the 'inheritance tree' the api.apiRoutes, No, these are for this specific party only, because the user propably, will have unexpected behavior when using Use/UseFunc, Done/DoneFunc return r.setName diff --git a/websocket.go b/websocket.go index df37dbbc..e6cab4fa 100644 --- a/websocket.go +++ b/websocket.go @@ -9,11 +9,11 @@ import ( // conversionals 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 = websocket.All - // NotMe is the string which the Emmiter use to send a message to all except this websocket.Connection + // NotMe is the string which the Emitter use to send a message to all except this websocket.Connection NotMe = websocket.NotMe - // Broadcast is the string which the Emmiter use to send a message to all except this websocket.Connection, same as 'NotMe' + // Broadcast is the string which the Emitter use to send a message to all except this websocket.Connection, same as 'NotMe' Broadcast = websocket.Broadcast )