Created
November 29, 2015 00:57
-
-
Save ilyabrin/f4f58d640e0309a4b46e to your computer and use it in GitHub Desktop.
Golang singleton pattern
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
| package singleton | |
| type singleton struct {} // private | |
| var instance *singleton // private | |
| // public method GetInstance | |
| func GetInstance() *singleton { | |
| if instance == nil { | |
| instance = &singleton{} | |
| } | |
| return instance | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment