go - net/context wrapped on the http.ResponseWriter, good or bad? -


i needed http router "violetear" support static , dynamic routing, mean, been available handle request like:

/read/book/:uuid/:uuid/  

:uuid c6ff0f6f-a274-48f4-b219-6595dcb989a5

or basic routes like:

/read/page/3 

for middleware used alice helped me keep things compatible http.handler interface.

so far good, until point needed exchange data between middleware or access named parameters, :uuid in previous example.

since router used in other projects wanted continue keeping compatibility http.handler interface, therefore decided not pass net/context argument between middleware , opted included in http.responsewriter specified here: https://github.com/nbari/violetear/blob/master/response_writer.go#l14.

with approach if need use context have like:

func handleuuid(w http.responsewriter, r *http.request) {     cw := w.(*responsewriter)     // add key-value pair context     cw.set("key", "my-value")     // print current value :uuid     fmt.fprintf(w, "named parameter:, %q", cw.get(":uuid")) } 

notice cw := w.(*responsewriter).

this working wondering if there issue doing type switch or if there concerns doing this.

thanks in advance.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -