mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-29 00:25:20 +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
|
||
|
}
|