I am new in Go language and I need some help. I have declared a global variable but the problem is that it does not keep its value. It would be solved with a static variable but no such variables exist in Go. How should I solve this?
gIDifelseLearner
I have to mention that NewLearner is called twice from two different files from different packages.
func NewLearner(name string, peerURLs types.URLs, clusterName string, now *time.Time) *Learner {
l := &Learner{
RaftAttributes: RaftAttributes{PeerURLs: peerURLs.StringSlice()},
Attributes: Attributes{Name: name},
}
var b []byte
sort.Strings(l.PeerURLs)
for _, p := range l.PeerURLs {
b = append(b, []byte(p)...)
}
b = append(b, []byte(clusterName)...)
if now != nil {
b = append(b, []byte(fmt.Sprintf("%d", now.Unix()))...)
hash := sha1.Sum(b)
l.ID = types.ID(binary.BigEndian.Uint64(hash[:8]))
gID=l.ID
return l
} else {
l.ID = gID
return l
}
}