mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-29 08:26:04 +03:00
21 lines
240 B
Go
21 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
|
||
|
}
|