awesome-patterns/creational/singleton/singleton.go
2017-11-09 20:22:11 +10:00

24 lines
294 B
Go

package singleton
type Singleton interface {
AddOne() int
}
type singleton struct {
count int
}
func (s *singleton) AddOne() int {
s.count++
return s.count
}
var instance *singleton
func GetInstance() Singleton {
if instance == nil {
instance = new(singleton)
}
return instance
}