Go to file
forest 0167ade391 change domain for go module :( 2024-01-15 20:33:18 +00:00
ReadMe.md readme formatting 2022-01-22 15:24:08 -06:00
go.mod change domain for go module :( 2024-01-15 20:33:18 +00:00
go.sum first commit, it works in go playground! 2022-01-19 22:37:47 -06:00
main.go clean up api 2022-01-22 15:23:28 -06:00

ReadMe.md

config-lite

A simple go library designed to be used by applications, in order to make them ez to configure.

It is intented to be simple, lightweight, and secure with great usability (no silent failures or cryptic error messages). It supports a single JSON file, environment variables, and/or command line flags.

This is the successor to my influx-style-env-override library.

TL;DR: keeps your configuration code easy, DRY, and eliminates silent config failures. It will warn you when you mess up!

Unrecognized environment variable 'TEST_BAZ_B'. Did you mean 'TEST_BAZ_0_B'?

Unrecognized commandline flag '-baz-0-b'. Did you mean '--baz-0-b'?

Unrecognized json field '.Baz[].b'. Did you mean '.Baz[].B'?

😤

usage example

import (
	"io/ioutil"
	"reflect"
	configlite "https://git.sequentialread.com/forest/config-lite"
)

type Config struct {
	Baz []Subconfig
}

type Subconfig struct {
	B int
}

func main() {
	config := Config{}
	ignoreCommandlineFlags := []string{}
	err := ReadConfiguration("config.json", "TEST", ignoreCommandlineFlags, reflect.ValueOf(&config))
	if err != nil {
		panic(err)
	}

	...
}

caveats

Right now this library cannot be mixed with other command line flag libraries, especially the stdlib one, because it won't work as soon as you provide a flag it doesn't know about.