I'm new to Golang, so highlighting in it makes me insane:
import "sync" type SyncMap struct { lock *sync.RWMutex hm map[string]string } func (m *SyncMap) Put (k, v string) { m.lock.Lock() defer m.lock.Unlock() m.hm[k] = v, true }
and then I just call:
sm := new(SyncMap) sm.Put("Test, "Test")
At this moment, I get a panic with a null pointer.
I worked on it using another function and call it right after new() :
func (m *SyncMap) Init() { m.hm = make(map[string]string) m.lock = new(sync.RWMutex) }
But I wonder if it is possible to get rid of this template initialization?
new-operator go
Illarion Kovalchuk Dec 21 '10 at 11:58 2010-12-21 11:58
source share