You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
forest 164dc71bce Update 'ReadMe.md' 2 years ago
ReadMe.md Update 'ReadMe.md' 2 years ago
go.mod fix package url 2 years ago
go.sum first commit, it works in go playground! 2 years ago
main.go clean up api 2 years ago

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 "git.sequentialread.com/forest/config-lite"
)

type Config struct {
	Baz []Subconfig
}

type Subconfig struct {
	B int
}

func main() {
	config := Config{}
	ignoreCommandlineFlags := []string{}
	err := configlite.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.