1
0
Fork 0
mirror of https://github.com/tmrts/go-patterns.git synced 2025-04-12 05:20:59 +00:00
go-patterns/singleton/singleton.go
2016-02-20 17:34:36 +02:00

20 lines
240 B
Go

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
}