m map[string]string
once sync.Once
e.once.Do(func() {
e.m = make(map[string]string)
})
// whatever else Run does
On Sunday, July 21, 2013 3:01:42 AM UTC-5, otiu...@gmail.com wrote:Based on my understanding it is a common practice for structs that require some sort initialization of private members, is that they have some sort of new function. Assuming the struct needed to have some sort of method called by the user to perform, wouldn't it just be nicer to implement lazy loading in that method? Like sync.Once.Example:type Ex struct {m map[string]stringonce sync.Once}func (e *Ex) Run() {e.once.Do(func() {e.m = make(map[string]string)})// whatever else Run does}