Implement singleton pattern

This commit is contained in:
Tamer Tas 2016-01-19 05:49:01 +02:00
parent a8f8670c1e
commit b0918f796a

20
singleton/singleton.go Normal file
View File

@ -0,0 +1,20 @@
package singleton
import (
"sync"
)
type Object struct {
}
var once sync.Once
var instance *Object
func GetInstance() *Object {
// Creates a singleton instance once.
once.Do(func() {
instance = &singleton{}
})
return instance
}