Categorygithub.com/stephenwithav/template
repositorypackage
0.2.0
Repository: https://github.com/stephenwithav/template.git
Documentation: pkg.go.dev

# README

Purpose

text/template chains methods together, which prevents some useful code patterns from being employed. This package wraps text/template and provides an Options-style interface.

Example from sqlc's internal code:

template.New("table").
    Funcs(funcMap).
	ParseFS(
		template,
		"templates/*.tmpl",
		"templates/*/*.tmpl*",
	)

Rewritten in Options style:

template.New("table",
	template.Funcs(funcMap),
	template.ParseFS(
		template,
		"templates/*.tmpl",
		"templates/*/*.tmpl*",
	))

Why does this matter?

It improves code reuse, enabling custom functionality like that in kobra.