【设计模式】【golang源码】 单例模式(Singleton Pattern)

单例模式目的:
对象初始化成本比较高,防止一个被屡次初始化。code

var (
    confOnce sync.Once // guards init of confVal via initConfVal
    confVal  = &conf{goos: runtime.GOOS}
)

// systemConf returns the machine's network configuration.
func systemConf() *conf {
    confOnce.Do(initConfVal)
    return confVal
}
相关文章
相关标签/搜索