3 ms·
One thing I've never quite understood is how a lot of Go code (including this blog post) handles package-level vars. Things like gorilla's CookieStore/Upgrader
by cjslep 12y ago
One thing I've never quite understood is how a lot of Go code (including this blog post) handles package-level vars. Things like gorilla's CookieStore/Upgrader or application-specific structs like a hub, database connection, or websocket pool could conceivably be singleton package-level vars, and in practice it seems like a lot of small-sized servers implement raw http.Handlers and just stick to using package vars.
I'm not trying to start a Singleton debate but I like to avoid using them where possible, so I always wind up writing http.Handler factories moreso than raw handlers. This comment may be a bit outside of this blog post but I am curious if package-level vars and raw Handlers are more idiomatic in Go than using factories to produce handlers and prevent package-level vars.
Edit:
Calls in the original post that made me think of this are calls such as:
user.FindUser(usr.Email)
cookies.LoginCookie(usr.Email)
...which may very well be package functions instead of struct member functions.