configwise

package module
v0.0.0-...-3c6165b Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 11 Imported by: 0

README

ConfigWise

Installation

go get -u github.com/gowool/configwise

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const (
	OpNew          = "configurer: new ->"
	OpUnmarshalKey = "configurer: unmarshal key ->"
	OpUnmarshal    = "configurer: unmarshal ->"
	OpOverwrite    = "configurer: overwrite ->"
	OpParseFlag    = "configurer: parse flag ->"
)

Variables

View Source
var (
	TagName = "cfg"
)

Functions

func ExpandVal

func ExpandVal(s string, mapping func(string) string) string

ExpandVal replaces ${var} or $var in the string based on the mapping function. For example, os.ExpandEnv(s) is equivalent to os.Expand(s, os.Getenv).

Types

type Configurer

type Configurer interface {
	// UnmarshalKey takes a single key and unmarshal it into a Struct.
	UnmarshalKey(name string, out interface{}) error

	// Unmarshal the config into a Struct. Make sure that the tags
	// on the fields of the structure are properly set.
	Unmarshal(out interface{}) error

	// Overwrite used to overwrite particular values in the unmarshalled config
	Overwrite(values map[string]interface{}) error

	// Get used to get config section
	Get(name string) interface{}

	// Has checks if config section exists.
	Has(name string) bool
}

func NewConfigurer

func NewConfigurer(options ...Option) (Configurer, error)

type Option

type Option func(*configurer)

func WithConfigMap

func WithConfigMap(configMap map[string]interface{}) Option

func WithFlags

func WithFlags(flags []string) Option

func WithName

func WithName(name string) Option

func WithPath

func WithPath(path string) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithReadInConfig

func WithReadInConfig(readInConfig []byte) Option

func WithType

func WithType(configType string) Option

Jump to

Keyboard shortcuts

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