Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Created April 29, 2016 08:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adohe-zz/08966e165878a433aaff7a2f268d2beb to your computer and use it in GitHub Desktop.
Save adohe-zz/08966e165878a433aaff7a2f268d2beb to your computer and use it in GitHub Desktop.
Golang singleton implementation
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