configo

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 1 Imported by: 0

README

configo

Build Status GitHub GoDoc Test Coverage Release

Dead simple handling of config structs containing optional values for your golang app!

Usage
import (
	"fmt"
	opt "github.com/romnnn/configo"
)

type myAppConfig struct {
	EnableExperimental *opt.Flag
}

var defaultConfig myAppConfig = myAppConfig{
	EnableExperimental: opt.SetFlag(false),
}

func main() {
	userConfig := myAppConfig{
		EnableExperimental: opt.SetFlag(true),
	}
	// Merge user config with the default config
	// Will only set values that have NOT been set
	// Otherwise, use OverrideConfig
	opt.MergeConfig(&userConfig, defaultConfig)
	didEnableExperimental := opt.Enabled(userConfig.EnableExperimental)
	fmt.Printf("EnableExperimental=%t\n", didEnableExperimental) // true
}

For more examples, see examples/.

Development
Prerequisites

Before you get started, make sure you have installed the following tools::

$ python3 -m pip install -U cookiecutter>=1.4.0
$ python3 -m pip install pre-commit bump2version invoke ruamel.yaml halo
$ go get -u golang.org/x/tools/cmd/goimports
$ go get -u golang.org/x/lint/golint
$ go get -u github.com/fzipp/gocyclo
$ go get -u github.com/mitchellh/gox  # if you want to test building on different architectures

Remember: To be able to excecute the tools downloaded with go get, make sure to include $GOPATH/bin in your $PATH. If echo $GOPATH does not give you a path make sure to run (export GOPATH="$HOME/go" to set it). In order for your changes to persist, do not forget to add these to your shells .bashrc.

With the tools in place, it is strongly advised to install the git commit hooks to make sure checks are passing in CI:

invoke install-hooks

You can check if all checks pass at any time:

invoke pre-commit

Note for Maintainers: After merging changes, tag your commits with a new version and push to GitHub to create a release:

bump2version (major | minor | patch)
git push --follow-tags
Note

This project is still in the alpha stage and should not be considered production ready.

Documentation

Index

Constants

View Source
const Version = "0.1.1"

Version is incremented using bump2version

Variables

This section is empty.

Functions

func Enabled

func Enabled(option *Flag) bool

Enabled ...

func FlagSet added in v0.1.1

func FlagSet(option *Flag) bool

FlagSet ...

func GetIntOrDefault added in v0.1.1

func GetIntOrDefault(i *Int, def int) int

GetIntOrDefault ...

func GetIntOrNil added in v0.1.1

func GetIntOrNil(i *Int) *int

GetIntOrNil ...

func MergeConfig

func MergeConfig(c Config, merge Config)

MergeConfig ...

func OverrideConfig

func OverrideConfig(c Config, override Config)

OverrideConfig ...

Types

type Config

type Config interface{}

Config ...

type Flag

type Flag struct {
	// contains filtered or unexported fields
}

Flag ...

func SetFlag added in v0.1.1

func SetFlag(enable bool) *Flag

SetFlag ...

type Int added in v0.1.1

type Int struct {
	// contains filtered or unexported fields
}

Int ...

func SetInt added in v0.1.1

func SetInt(value int) *Int

SetInt ...

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL