Canonical guidance

Use when

Avoid

Preferred pattern

type Config struct {
	Addr string
}

func LoadConfig() Config {
	var cfg Config
	ready := make(chan struct{})

	go func() {
		cfg = loadConfig()
		close(ready)
	}()

	<-ready
	return cfg
}

Anti-pattern

Explanation: This anti-pattern is common when tests seem stable, but visibility bugs can stay hidden until production interleavings expose them.

Why

Sources