Skip to content

How do I convert a Handle to a HandleFunc?

pikachule edited this page Sep 12, 2017 · 1 revision
https://stackoverflow.com/questions/27614932/how-do-i-convert-a-handle-to-a-handlefunc
github.com/dchest/captcha
github.com/gorilla/mux

ou can convert the http.Handler h to a http.HandlerFunc using the method expression:

h.ServeHTTP

Instead of converting to a HandlerFunc, you can register the Handler directly using the route Handler method:

router.Methods("GET").Path("/captcha/").Handler(captcha.Server(captcha.StdWidth, captcha.StdHeight))

Based on your comments and edits, I think you want a prefix match instead of an exact match:

router.Methods("GET").PathPrefix("/captcha/").Handler(captcha.Server(captcha.StdWidth, captcha.StdHeight))

Clone this wiki locally