Original post

Morning, folks

               So was learning myself a bit of text/template package when I came across this supposedly common error. Did a minor search on ’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.

package something

import (

type Entry func() string
var Registry []Entry = []Entry{Summary, A, B}

func Summary() string {
        buf := &bytes.Buffer{}
        str := "{{.}}"
        tlp := template.Must(template.New("Summ").Parse(str))
        tlp.Execute(buf, Registry)
        return buf.String()

func A() string {
        return "a"

func B() string {
        return "b"

Will endup with an error similar to this:

# something
something.go:?:?: initialization loop:
        .../something.go:?:?: Registry refers to
        .../something.go:?:?: Summary refers to
        .../something.go:?:?: Registry