How does one implement the Singleton design pattern in the go programming language?
You should be aware that Once.Do
is serious about executing the code only once. That means, the code is always executed only once, even though it might have panicked:
from https://golang.org/pkg/sync/#Once.Do
If f (note: the once logic) panics, Do considers it to have returned; future calls of Do return without calling f.
I used mutexes instead to ensure unique initialisation of a global configuration variable to overcome this restriction: