3 ms·
If what you're trying to achieve is to pump out some HTML, Go has built-in safe HTML templating. The template syntax isn't glamorous (in fact it can be very unp
by ovao 9y ago
If what you're trying to achieve is to pump out some
HTML, Go has built-in safe HTML templating. The template syntax isn't glamorous (in fact it can be very unpleasant at times), but with it you can catch type errors at parse time, and the ability to bind custom functions on your templates comes in handy.
Usefully, too, any type that implements the Stringer interface can be dropped into a template and will come out of it as a string without any additional fussing. If your app implements a number of custom types, it's actually possible to get Go templates to look relatively sane.