Skip to content

Instantly share code, notes, and snippets.

@tqcenglish
Last active March 16, 2020 12:35
Show Gist options
  • Save tqcenglish/091bbd1879867074916e20f7fd51b7c8 to your computer and use it in GitHub Desktop.
Save tqcenglish/091bbd1879867074916e20f7fd51b7c8 to your computer and use it in GitHub Desktop.
go 单例模式
//https://studygolang.com/articles/11444
type singleton struct{}
var ins *singleton
var once sync.Once
func GetIns() *singleton {
once.Do(func(){
ins = &singleton{}
})
return ins
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment