andreiavrammsd / config

Load configuration values into given struct from environment, files or other input.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Config

codecov

Package config load configuration values into given struct.

The struct must be passed by reference.

Fields must be exported. Unexported fields will be ignored. They can have the env tag which defines the key of the value. If no tag provided, the key will be the uppercase full path of the field (all the fields names starting the root until current field, joined by underscore).

The json tag will be used for loading from JSON.

package main

import (
	"fmt"
	"log"

	"github.com/andreiavrammsd/config"
)

type Config struct {
	Username string `env:"USERNAME"`
	Tag      string `env:"TAG" default:"none"`
}

func main() {
	input := []byte(`USERNAME=msd # username`)

	cfg := Config{}
	if err := config.Load(&cfg).Bytes(input); err != nil {
		log.Fatalf("cannot load config: %s", err)
	}

	fmt.Println(cfg.Username)
	fmt.Println(cfg.Tag)
}

Docs

GoDoc

Install

go get github.com/andreiavrammsd/config

Usage

See examples and tests.

Testing and QA tools for development

See Makefile.

About

Load configuration values into given struct from environment, files or other input.

License:MIT License


Languages

Language:Go 96.4%Language:Makefile 3.6%