Last active
August 29, 2015 14:24
-
-
Save andboson/49a7e6b1fdd57389d261 to your computer and use it in GitHub Desktop.
singleton pattern in go
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 | |
import ( | |
"sync" | |
) | |
//http://marcio.io/2015/07/singleton-pattern-in-go/ | |
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