Skip to content

Configuration

Akshay Katyal edited this page Jun 9, 2022 · 1 revision

The configuration in the framework is managed using environment variables. Whenever you run the docker-compose files, .env file is expected to be present in the docker folder wherein all the configuration variables are automatically picked up & added to the environment. Each config variable is then read in the config package using https://github.com/spf13/viper.

config package holds the entire configuration of the service. For each type of configuration, there is a separate file in the config package, for ex: api.go, postgres.go, objectstorage.go etc. Feel free to add new variables in the same files or new files to the codebase as you contribute.

Demystifying a config file

Each config file like api.go, postgres.go etc has the following sections

private struct

This is the struct for the config type which holds the config variables as the member variables

load() method

This method reads all the variables from the environment & loads them onto the member variables of the struct

config.go

The config.go file in the config package is the file that ties all the config together.

config struct

This is the main struct for the config which takes all the config type variables as the member variables

Load() method

This method calls the load method of all the config structs into the singleton configuration variable. This method is automatically called as the first line in main.go

Accessor methods

Each configuration variable (no matter which type) has an accessor method in the config.go file. Whenever you want to access a config variable anywhere, you should be using these accessor methods to get the config value.

Clone this wiki locally