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
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
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
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