The Go embed package lets you embed files into the compiled application, so you don’t need to publish templates separately. Of course there are advantages and disadvantages to this approach. Here we’re storing the templates in a map, with constants for the keys. The default behavior is to only parse the template on demand when […]
Seems there’s no standard or official way to load configuration files in Go. There are libraries out there, but if you’re just looking for something simple, you’d just read a JSON file into your application. config/configuration.go config/email.go conf.json main.go
When you’ve got a dangerous function, like one that grabs an element from a slice by index, you can wrap it in a safe function that returns the result or an error instead. Use the defer feature to recover from a panic if it exists, and return an error instead.