Re: [go-nuts] Avoid global variables in Http handlers

2019-06-09 Thread sethamclean
You are passing the struct and not the method on the struct to the handle function. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googl

Re: [go-nuts] Avoid global variables in Http handlers

2019-06-04 Thread Tong Sun
Oh, yeah, that works. Thanks Aldrin. The reason that I'm asking is that the "solution" that I found on the web isn't working for me: Here is a BETTER example (not using global variables): type specificHandler struct { Thing string} func (h *specificHandler) ServeHTTP(w http.ResponseWriter

Re: [go-nuts] Avoid global variables in Http handlers

2019-06-03 Thread Aldrin Leal
wrapping into a typedef? typedef MyHandler struct { GlobalThing string } func (h *MyHandler) handle(w http.ResponseWriter, r *http.Request) { } func main() { h := MyHandler{} http.HandleFunc("/", MyHandler.handle) } -- -- Aldrin Leal, / https://ingenieux.io/about/ On Mon, Jun 3, 2019

[go-nuts] Avoid global variables in Http handlers

2019-06-03 Thread Tong Sun
Here is a BAD example (using global variables): var globalThing string func specificHandler(w http.ResponseWriter, r *http.Request) { w.Write(globalConfigThing)} func main() { globalThing = "Hello world!" http.HandleFunc("/something", specificHandler) http.ListenAndServe(":808