Singleton
package army
var (
once sync.Once
commander *General
)
// Outside of this package, no one can access this struct except through NewGeneral()
type general struct {
Army Army
}
func NewGeneral(armySize int) *general {
once.Do(func() {
commander = &general{Army: New(armySize)}
})
return commander
}Last updated