Skip to content

Instantly share code, notes, and snippets.

@Bebbolus
Last active December 4, 2018 17:05
Show Gist options
  • Save Bebbolus/ac42e63867c56bfdb5b2610155095b6b to your computer and use it in GitHub Desktop.
Save Bebbolus/ac42e63867c56bfdb5b2610155095b6b to your computer and use it in GitHub Desktop.
for _, mid := range v.Middlewares {
//load middleware plugin
plug, midErr := plugin.Open(mid.Handler)
if midErr != nil {
log.Fatalf(midErr)
os.Exit(-1)
}
//look up the Middleware type
symMiddleware, midErr := plug.Lookup("Middleware")
if midErr != nil {
log.Fatalf(midErr)
os.Exit(-1)
}
//check that loaded symbol is type Middleware
var middleware Middleware
middleware, ok := symMiddleware.(Middleware)
if !ok {
log.Fatalf("The middleware module have wrong type")
os.Exit(-1)
}
//build the gate function that contain the middleware funcition instance with args
nmid := Gate(middleware.Pass(mid.Params))
//append to the middlewares chain
chain = append(chain, nmid)
}
// Use all the modules to handle the request
http.HandleFunc(v.Path, Chain(controller.Fire, chain...))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment