From 98735a5a93955ba11633fa8f991c95660510851a Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Fri, 22 Sep 2017 10:00:44 -0300 Subject: [PATCH] Add a way to extend the handlers and add custom stuff --- api.go | 2 +- handlers/bootstrap.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index 2c948b6..0d13baf 100644 --- a/api.go +++ b/api.go @@ -42,7 +42,7 @@ func main() { sch.Start() handlers.Bootstrap(core, e) - handlers.Register() + handlers.Register(nil) } func initStorage() storage.StorageApi { diff --git a/handlers/bootstrap.go b/handlers/bootstrap.go index d73e447..772cd81 100644 --- a/handlers/bootstrap.go +++ b/handlers/bootstrap.go @@ -25,12 +25,14 @@ var core pwd.PWDApi var e event.EventApi var ws *socketio.Server +type HandlerExtender func(h *mux.Router) + func Bootstrap(c pwd.PWDApi, ev event.EventApi) { core = c e = ev } -func Register() { +func Register(extend HandlerExtender) { bypassCaptcha := len(os.Getenv("GOOGLE_RECAPTCHA_DISABLED")) > 0 @@ -91,6 +93,10 @@ func Register() { corsRouter.HandleFunc("/", NewSession).Methods("POST") + if extend != nil { + extend(corsRouter) + } + n := negroni.Classic() r.PathPrefix("/").Handler(negroni.New(negroni.Wrap(corsHandler(corsRouter)))) n.UseHandler(r)