Duck pass context values to all handler for a request, and clear the context after the request ends.
- Use
SetContext()
andGetContext()
. - Provide a Middleware to delete context when request ends.
package main
import (
"github.com/go-zoo/duck"
)
func main() {
mux := http.NewServeMux()
mux.Handle("/", TestHandler)
http.ListenAndServe(":8080", duck.UseContext(mux))
}
func TestHandler(rw http.ResponseWriter, req *http.Request) {
duck.SetContext(req, "id", "test")
rw.Write([]byte(duck.GetContext(req, "id")))
}
- DOC
- Refactoring
- Debugging
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Write Tests!
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
MIT
Lightning Fast HTTP Mux : Bone