So was learning myself a bit of text/template package when I came across this supposedly common error. Did a minor search on Go’s Github issues and here, but to no success. I know the reference cycle exists, but shouldn’t this be already dealt with? Here’s a small chunk of code.
That is interesting. I can reproduce it. The way I was able to get around it was by putting the initialization of Registry into an init function like this:
Thanks for the answer, Sean. Totally forgot about init(). Good to know its a way out, but looking at https://golang.org/doc/effective_go.html#init, I’m not sure its original purpose was to avoid that kind of technical detail. Besides this cryptic line Besides initializations that cannot be expressed as declarations,, init()'s purpose seems to be to initialize stuff in a singleton manner.