[go-nuts] constructors vs lazy initialization

2018-03-03 Thread Jérôme LAFORGE
Not sure that is relevant for your example, but if do can be called by multiple goroutines, then you have to use atomic.Once (store within the struct) in order to initialize. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from

[go-nuts] constructors vs lazy initialization

2018-03-03 Thread 'Anmol Sethi' via golang-nuts
How do you guys choose between constructors and lazy initialization? For example. Struct constructors: type meow struct { x http.Handler } func newMeow() *meow { return &meow{ x: http.NewServeMux(), } } func (m *meow) do() { // stuff } Lazy initialization: type meow