awesome-patterns/singleton/singleton.go

21 lines
240 B
Go
Raw Normal View History

2016-01-19 06:49:01 +03:00
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
}