Skip to content

Instantly share code, notes, and snippets.

@yumed15
Created November 24, 2023 11:52
Show Gist options
  • Save yumed15/b7ff70f84d8b58cdb7a54871a6da20cc to your computer and use it in GitHub Desktop.
Save yumed15/b7ff70f84d8b58cdb7a54871a6da20cc to your computer and use it in GitHub Desktop.
var once sync.Once
var singletonInstance *MySingleton
func createSingleton() {
singletonInstance = new(MySingleton)
}
func getSingleton() *MySingleton {
once.Do(createSingleton)
return singletonInstance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment