Reading Config Files
Load YAML, JSON, TOML.
Configuration Lives Outside Code
Hardcoding values like ports, hostnames, and timeouts into your Go program is fragile. Viper is the de-facto configuration library for Go: it reads settings from files, environment variables, flags, and remote stores.
In this lesson you load configuration from a file on disk.
What Formats Viper Reads
Viper supports many formats out of the box:
- YAML (
.yaml/.yml) - JSON (
.json) - TOML (
.toml) - HCL, INI, and Java properties files
You pick the format with SetConfigType, or Viper infers it from the file extension.
All lessons in this course
- Reading Config Files
- Environment Variables
- Defaults and Watching
- Binding to Structs