You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minimine or remove use of the init() function and replace with a client invocable bootstrap function
library code tends to go under a directory named pkg. Therefore, we should rename our lib directory to pkg and leave it as that (remember to update the readme)
It is not practical to entirely remove all package scope varaibles. We can use const variables to minimise the potential of harm in multi-threaded context. The rationale for wanting to eliminate package globals is the problem of concurrent access to shared state. If this state is private and created as const, then this is ok. The user should be wary of creating non const state that can be modified by the client. If you do want package state, try to restrict this to read only entities and provide public getter method.
If a public var is used, it should not be the default behaviour to expose it as it implementation type. You want to minimise the exposed surface by the use of an interface, eg it would better to expose an variable as io.Reader instead of its implementation type.
Inspiration for this issue came from these youtube videos:
You might also need to look at go-build-tmeplatate for more refactoring ideas and also using-domain-driven-design-ddd-in-golang
Also see: go-without-package-scoped-variables
The text was updated successfully, but these errors were encountered: