awesome-patterns/creational/singleton/singleton.go

24 lines
294 B
Go
Raw Normal View History

2017-11-09 13:22:11 +03:00
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
}