package design
import (
"fmt"
"sync"
)
type singleTon struct {
}
func (s *singleTon) Show() {
fmt.Println("hello world")
}
var (
once sync.Once
single *singleTon
)
func GetSingleInstance() *singleTon {
once.Do(func() {
single = &singleTon{}
})
return single
}
go 设计模式——单例模式
最新推荐文章于 2024-08-21 22:31:49 发布