0PricingLogin
Go Academy · Lesson

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

  1. Reading Config Files
  2. Environment Variables
  3. Defaults and Watching
  4. Binding to Structs
← Back to Go Academy