Last active
August 29, 2015 14:23
-
-
Save nihtalak/54a43d72c6e132c2a333 to your computer and use it in GitHub Desktop.
Injected context
This file contains hidden or 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
| struct Context { | |
| db *sql.DB | |
| } | |
| struct AppHandler { | |
| context *Context | |
| hanlder func(response http.ResponseWriter, request *http.Request, _ httprouter.Params) | |
| } | |
| func (ah AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| ah.handler(ah.context, w, r) | |
| } | |
| func main() { | |
| context = &InitContext() | |
| router.GET("/", AppHandler{context, Handler}) | |
| } | |
| func Handler(context *Context, w http.ResponseWriter, r *http.Request) (int, error) { | |
| // access to db via | |
| context.db.Query() | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesnt work with https://github.com/julienschmidt/httprouter