Skip to content

Instantly share code, notes, and snippets.

@nazariyv
Created August 20, 2020 20:04
Show Gist options
  • Save nazariyv/672f0297c7cfd14237f9f5c3c3cc5923 to your computer and use it in GitHub Desktop.
Save nazariyv/672f0297c7cfd14237f9f5c3c3cc5923 to your computer and use it in GitHub Desktop.
go-singleton
var once sync.Once
// type global
type singleton map[string]string
var instance singleton
func NewClass() singleton {
once.Do(func() { // <-- atomic, does not allow repeating
instance = make(singleton) // <-- thread safe
})
return instance
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment