Last active
March 16, 2020 12:35
-
-
Save tqcenglish/091bbd1879867074916e20f7fd51b7c8 to your computer and use it in GitHub Desktop.
go 单例模式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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