How it works...
Reading and writing environment variables is pretty simple with the os package. The envconfig third-party library this recipe uses is a clever way to capture environment variables and specify certain requirements using struct tags.
The LoadConfig function is a flexible way to pull in configuration information from a variety of sources without a lot of overhead or too many extra dependencies. It would be simple to convert the primary config into another format aside from JSON or just always use environment variables as well.
Also, note the use of errors. We wrap errors throughout the code in this recipe so that we can annotate errors without losing the original error information. There will be more details on this in Chapter ...
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