Skip to content

Instantly share code, notes, and snippets.

@groovili
Forked from jackypanster/singleton.go
Created July 6, 2018 08:14
Show Gist options
  • Save groovili/278aee87ee6300341897ca4da4fb683e to your computer and use it in GitHub Desktop.
Save groovili/278aee87ee6300341897ca4da4fb683e to your computer and use it in GitHub Desktop.
singleton in golang
package singleton
import (
"sync"
)
type singleton struct {
}
var instance *singleton
var once sync.Once
func GetInstance() *singleton {
once.Do(func() {
instance = &singleton{}
})
return instance
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment