Settings parses command line and environment variables on one line. And makes it available throughout the code base. Making using settings in your project as boring and unimportant as it should be. Settings vars is as simple as:
settingo.Set("FOO", "default value", "help text")
Getting vars out has the same level of complexity as setting the value.
settingo.Get("FOO")
- Simplicity: Set up settings within a single line of code.
- Flexibility: Utilize command-line flags, environment variables, or defaults.
- Typesafety: Seamlessly work with strings, integers, booleans, and maps.
- Convenience: Global access with a singleton pattern.
- User-friendly: Automatic --help flag generation for your applications.
- Versatility: Works flawlessly in Linux, Docker, Kubernetes, and other environments.
example of how to use. More can be found in the example_project
package main
import (
"fmt"
"github.com/Attumm/settingo/settingo"
)
func main() {
settingo.Set("FOO", "default value", "handy help text")
settingo.Parse()
fmt.Println("foo =", settingo.Get("FOO"))
}
The above go will produce binary that can be used as follows. Get handy help text set in the above example on the same line. This can get very handy when the project grows and is used in different environments
$ ./example --help
Usage of ./example:
-FOO string
handy help text (default "default value")
When no value is given, default value is used
$ ./example
foo = default value
Running the binary with command line input
$ ./example -FOO bar
foo = bar
Running the binary with environment variable
$ FOO=ok;./example
foo = ok
variables are set with preference variables on the command line will have highest preference. This because while testing you might want to override environment The priority order is as follows
- Command line input
- Environment variables
- Default values
Settingo supports different types.
// string
settingo.Set("FOO", "default", "help text")
settingo.Get("FOO")
// integer
settingo.SetInt("FOO", 42, "help text")
settingo.GetInt("FOO")
// boolean
settingo.SetBool("FOO", true, "help text")
settingo.GetBool("FOO")
// map
defaultMap := make(map[string][]string)
defaultMap["foo"] = []string{"bar"}
settingo.SetMap("FOO", defaultMap, "help text")
settingo.GetMap("FOO")
go get "github.com/Attumm/settingo/settingo"
Handy example_project as starting point.
MIT