mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-26 21:56:02 +03:00
19 lines
282 B
Go
19 lines
282 B
Go
package singleton
|
|
|
|
import "sync"
|
|
|
|
//Singleton 是单例模式类
|
|
type Singleton struct{}
|
|
|
|
var singleton *Singleton
|
|
var once sync.Once
|
|
|
|
//GetInstance 用于获取单例模式对象
|
|
func GetInstance() *Singleton {
|
|
once.Do(func() {
|
|
singleton = &Singleton{}
|
|
})
|
|
|
|
return singleton
|
|
}
|