Go language supports built-in template functionality. Packages with this support include 1) text/template and; 2) html/template.
Overview
Go language supports built-in template functionality. This is provided by the text/template
and html/template
packages. Go templates can be used as a minimal scripting language within command-line tools, or embedded in tools to produce larger files.
Features
Go language templates support most of the traditional features found in template-engines including, but not limited to:
- comments
- template variables and expressions
{{
}}
template placeholder syntax (known asactions
)
Related Tools
Go templates are widely used in the greater kubernetes ecosystem. A template can be used to render output of the kubectl command-line tool, or in combination with the kubernetes-helm package manager to produce Kubernetes object manifests based on deploy-time settings.
Tag Guidance
Go templates are not Go code. Use the go tag only if you are writing code that invokes one of the template packages; do not use it if you are writing template code using another tool using the template engine.
If you are using Go templates in the context of another tool such as kubernetes-helm or helmfile, also use the appropriate tag for that tool. If you are using a support library such as sprig-template-functions, it may be appropriate to include this tag as well.
Go templates share many aspects of traditional programming, including variables, loops, and subroutines. It is possible to use Go templates in non-programming contexts as well. For simple applications merely involving variable substitution or rendering a structure in the --format
option of a command-line tool, consider whether your use is actually programming-related.