mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 22:36:05 +03:00
01aad3573b
Signed-off-by: Bruce <weichou1229@gmail.com>
28 lines
368 B
Go
28 lines
368 B
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
// singleton is private struct, it should be created and fetched by GetSingletonObject func
|
|
type singleton struct {
|
|
}
|
|
|
|
func (singleton) SayHi() {
|
|
fmt.Println("Hi!")
|
|
}
|
|
|
|
var (
|
|
once sync.Once
|
|
instance singleton
|
|
)
|
|
|
|
func GetSingletonObject() singleton {
|
|
once.Do(func() {
|
|
instance = singleton{}
|
|
})
|
|
|
|
return instance
|
|
}
|