GoLand 2020.2 Help

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.

Define mapping of a type between Go template and application

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*/ -}}.

  1. Add an HTML tag (for example, <title></title>).

  2. Inside an HTML tag, type {{.}}.

  3. Place the caret after the dot, press Alt+Enter, and select Specify dot type.

  4. In the gotype comment section, select the necessary type from the code completion popup Ctrl+Space.

Define mapping of a type between Go template and application

Files on GitHub.

Last modified: 08 May 2020