diff options
author | Chris <ccbrown112@gmail.com> | 2017-09-12 09:19:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-12 09:19:52 -0500 |
commit | b066b6df138e88e75cb40f1ec3e58fbd13e61909 (patch) | |
tree | 7ee0e8c935cd3bbafd15d0d07d8900af8b82a4e0 /api/api.go | |
parent | 674a606bd00b276d0a05b3b29a3d5f5e5e7f8206 (diff) | |
download | chat-b066b6df138e88e75cb40f1ec3e58fbd13e61909.tar.gz chat-b066b6df138e88e75cb40f1ec3e58fbd13e61909.tar.bz2 chat-b066b6df138e88e75cb40f1ec3e58fbd13e61909.zip |
Remove global app references (#7433)
* remove global app references
* test fix
* fix api4 test compilation
Diffstat (limited to 'api/api.go')
-rw-r--r-- | api/api.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/api/api.go b/api/api.go index 8e8064731..313cbc7e1 100644 --- a/api/api.go +++ b/api/api.go @@ -59,15 +59,16 @@ type Routes struct { var BaseRoutes *Routes -func InitRouter() { - app.Global().Srv.Router = mux.NewRouter() - app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404) +func NewRouter() *mux.Router { + ret := mux.NewRouter() + ret.NotFoundHandler = http.HandlerFunc(Handle404) + return ret } -func InitApi() { +func InitApi(root *mux.Router) { BaseRoutes = &Routes{} - BaseRoutes.Root = app.Global().Srv.Router - BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter() + BaseRoutes.Root = root + BaseRoutes.ApiRoot = root.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter() BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter() BaseRoutes.NeedUser = BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter() BaseRoutes.Teams = BaseRoutes.ApiRoot.PathPrefix("/teams").Subrouter() @@ -111,7 +112,7 @@ func InitApi() { InitDeprecated() // 404 on any api route before web.go has a chance to serve it - app.Global().Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404)) + root.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404)) utils.InitHTML() |