Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions design/singleton/go_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ package singleton

import "sync"

type singleton struct{}

var (
goInstance *Instance
ins *singleton
once sync.Once
)

// 使用go 实现单例模式
func GetIns() *singleton {
func GoInstance(name string) *Instance {
once.Do(func() {
ins = &singleton{}
goInstance = &Instance{Name: name}
})
return ins
return goInstance
}