Go templates
Go has its own template engine that is split into two packages: text/template and html/template. These packages are similar in functionality, with the difference that html/template allows a user to generate HTML code that is safe against code injection, making it suitable for use on web pages and emails. Also, these packages provide code assistance in other applications such as the configuration for Helm and the Kubernetes package manager.
To specify mapping of a type between a Go template and an application, GoLand uses the gotype
comment of the following structure: {{- /*gotype: package/import/path.type_name*/ -}}
.
Define mapping of a type between Go template and application
Add an HTML tag (for example,
<title></title>
).Inside an HTML tag, type
{{.}}
.Place the caret after the dot, press Alt+Enter, and select Specify dot type.
In the
gotype
comment section, select the necessary type from the code completion popup Ctrl+Space.