Templating
Although JSON can be the best choice when complex data structures have to be shared across software programs, this is not the case, in general, when the HTTP server is supposed to be consumed by humans. In the previous exercises and activities, the chosen way to format a text has been the fmt.Sprintf
function, which is good for formatting texts, but is simply insufficient when a more dynamic and complex text is required. As you will have noticed in the previous exercise, the message returned in case a name was passed as a parameter to the URL observed a specific pattern, and this is where a new concept comes in – the template. A template is a skeleton from which complex entities can be developed. Essentially, a template is like a text with some blanks, and a template engine will take some values and fill the blanks, as you can see in the following diagram:
As you can see, {{name}}
is a placeholder and, when...