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, <[email protected]> / https://ingenieux.io/about/
On Mon, Jun 3, 2019 at 10:48 PM Tong Sun <[email protected]> wrote:
>
> 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(":8080", nil)}
>
>
> How to avoid using global variables?
>
> thx
>
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/1bc9f505-9638-49e2-b873-6f4d7b88dfbc%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/1bc9f505-9638-49e2-b873-6f4d7b88dfbc%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CALpo8NtfwgfpvB_3OnR-fV4qTgrw7grw_-Sc3YZGJqOfuS1hYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.