Last active
July 5, 2019 09:42
-
-
Save xin053/faed5986bb5852326de092975c870eb9 to your computer and use it in GitHub Desktop.
[go singleton] go singleton #go #singleton
This file contains hidden or 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
| // 通过 sync/Once 实现单例 | |
| var ( | |
| instance *singleton | |
| once sync.Once | |
| ) | |
| func Instance() *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