Skip to content

Instantly share code, notes, and snippets.

@gudata
Forked from adohe-zz/singleton.go
Created May 19, 2019 16:12
Show Gist options
  • Save gudata/576958d59ab7fd54ff57d043ccf7be13 to your computer and use it in GitHub Desktop.
Save gudata/576958d59ab7fd54ff57d043ccf7be13 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