Implement singleton pattern

This commit is contained in:
Tamer Tas committed 2016-02-20 17:34:36 +02:00
1 parent a8f8670c1e
commit b0918f796a
1 file changed
+20
+20
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
}