Locating Configuration Files
Explore how to locate and specify configuration files in Go programs using the Viper library. Learn to define search paths, set configuration names and file types, and manage multiple config formats. This lesson helps you control where and how your Go command-line applications find and load configuration data.
We'll cover the following...
Configuration files are a staple of program configuration, especially when the configuration data is complicated and hierarchical in nature. Viper supports a large number of configuration files, including JSON, TOML, YAML, HCL, INI, envfile and Java Properties files. In this lesson, you will see how to locate the configuration file. Later, we will see how to write configuration files, how to read them and even how to watch them for changes.
Overview
When working with configuration files there are several tasks. First, you need to locate where the configuration file is, and then you need to read and parse its contents. Under some circumstances, you may also want to write or update a configuration file from your program. For more dynamic situations, it’s important to be able to watch a configuration file for changes and re-read it to reflect the configuration changes. Let’s see how Viper allows you to perform all these tasks.