Text templating
Go has a built-in templating language, text/template, that implements templates with data and generates a text-based output. We use structs in order to define the data that we want to use within our templates. As with all things, Go input text is defined as UTF-8 and can be passed in as any format. We use double braces {{}} to denote actions that we want to perform on our data. A cursor, represented by ., allows us to add data to our template. These things combined create a powerful templating language that will allow us to reuse templates for many bits of code.
First, we are going to initialize our package, import our necessary dependencies, and define our struct for the data that we would like to pass into our template: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access