Last active
December 4, 2018 17:05
-
-
Save Bebbolus/ac42e63867c56bfdb5b2610155095b6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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