go的单例模式可以使用系统自带的sync的包。
import "sync"
type Singleton struct {
}
var one sync.Once
var SingletonInstance * Singleton
func (this* Singleton) getInstance() *Singleton{
one.Do(func() {
SingletonInstance = new singleton()
return SingletonInstance
}
)
}