mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-12-01 17:36:09 +03:00
24 lines
294 B
Go
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
|
||
|
}
|