1
0
Fork 0
gobelt/config
Gregory Eremin 993153693a Move readme parts to their corresponding packages 2018-07-03 20:33:55 +02:00
..
README.md Move readme parts to their corresponding packages 2018-07-03 20:33:55 +02:00
config.go Break it 2018-06-25 00:22:27 +02:00
config_test.go Use file contents for config test 2018-07-03 19:46:54 +02:00

README.md

Config

Package config allows other packages to require a certain section of TOML configuration file to be parsed into its internal configuration structure. Once config file is processed its values are distributed by the packages that required them.

import "github.com/localhots/gobelt/config"

Describe configuration structure inside a target package then call config.Require from the init function of a package.

Note: subgroups are not currently supported. If a package is called s3 and located in aws parent package, call config section aws_s3 instead of aws.s3.

package db

var conf struct {
    Flavor string `toml:"flavor"`
    DSN    string `toml:"dsn"`
}

func init() {
    config.Require("db", &conf)
}

Load configuration from a main function of the app:

package main

func main() {
    config.Load("config/config.toml")
}