-
Notifications
You must be signed in to change notification settings - Fork 41
Description
The current implementation defines and uses a package-level variable for the *superTokens
instance
which is not a great if anyone would like to have multiple instances or for testing (in parallel).
Instead it should be handled in encapsulation, for example by changing the func supertokensInit(config TypeInput) error {}
and func Init(config TypeInput) error {}
functions to return a *superTokens
object and by making type superTokens struct {}
a public struct:
type SuperTokens struct {}
func supertokensInit(config TypeInput) (error, *SuperTokens) {}
func Init(config TypeInput) (error, *SuperTokens) {}
Maybe Init(config TypeInput)
should even be renamed to NewSuperTokens
or NewSuperTokensInstnace
.
To me this implementation is not very idiomatic Go and looks more like JavaScript.
This would probably a bigger change affecting various parts of the SDK.
Edit: After using the SDK a bit more, I've realized that almost every type has a singleton instance. This is not very flexible and definitely not a good design pattern. Basically all singletons should be removed and refactored with more structure in mind.