Documentation
¶
Index ¶
- Constants
- Variables
- type Fig
- type Fruit
- type ListFlag
- type MapFlag
- type Mutagenesis
- type Mutation
- type Options
- type Tree
- func (fig *Tree) Bool(name string) *bool
- func (fig *Tree) Curse()
- func (fig *Tree) Duration(name string) *time.Duration
- func (fig *Tree) ErrorFor(name string) error
- func (fig *Tree) Float64(name string) *float64
- func (fig *Tree) Int(name string) *int
- func (fig *Tree) Int64(name string) *int64
- func (fig *Tree) List(name string) *[]string
- func (fig *Tree) Load() (err error)
- func (fig *Tree) LoadFile(path string) (err error)
- func (fig *Tree) Map(name string) *map[string]string
- func (fig *Tree) MutagensisOf(what interface{}) Mutagenesis
- func (fig *Tree) MutagensisOfFig(name string) Mutagenesis
- func (fig *Tree) Mutations() <-chan Mutation
- func (fig *Tree) NewBool(name string, value bool, usage string) *bool
- func (fig *Tree) NewDuration(name string, value time.Duration, usage string) *time.Duration
- func (fig *Tree) NewFloat64(name string, value float64, usage string) *float64
- func (fig *Tree) NewInt(name string, value int, usage string) *int
- func (fig *Tree) NewInt64(name string, value int64, usage string) *int64
- func (fig *Tree) NewList(name string, value []string, usage string) *[]string
- func (fig *Tree) NewMap(name string, value map[string]string, usage string) *map[string]string
- func (fig *Tree) NewString(name string, value string, usage string) *string
- func (fig *Tree) NewUnitDuration(name string, value, units time.Duration, usage string) *time.Duration
- func (fig *Tree) Parse() (err error)
- func (fig *Tree) ParseFile(filename string) (err error)
- func (fig *Tree) Recall()
- func (fig *Tree) Reload() error
- func (fig *Tree) Resurrect(name string)
- func (fig *Tree) Store(mut Mutagenesis, name string, value interface{}) Fruit
- func (fig *Tree) StoreBool(name string, value bool) Fruit
- func (fig *Tree) StoreDuration(name string, value time.Duration) Fruit
- func (fig *Tree) StoreFloat64(name string, value float64) Fruit
- func (fig *Tree) StoreInt(name string, value int) Fruit
- func (fig *Tree) StoreInt64(name string, value int64) Fruit
- func (fig *Tree) StoreList(name string, value []string) Fruit
- func (fig *Tree) StoreMap(name string, value map[string]string) Fruit
- func (fig *Tree) StoreString(name, value string) Fruit
- func (fig *Tree) StoreUnitDuration(name string, value, units time.Duration) Fruit
- func (fig *Tree) String(name string) *string
- func (fig *Tree) UnitDuration(name string) *time.Duration
- func (fig *Tree) Usage() string
- func (fig *Tree) WithValidator(name string, validator func(interface{}) error) Fruit
- type ValidatorFunc
Constants ¶
const ( DefaultYAMLFile string = "config.yml" // Default filename for a YAML configuration file DefaultJSONFile string = "config.json" // Default filename for a JSON configuration file DefaultINIFile string = "config.ini" // Default filename for a INI configuration file VERSION = "v1.0.1" )
Variables ¶
var AssureBoolFalse = func(value interface{}) error { if v, ok := value.(bool); ok { if v { return fmt.Errorf("value must be false, got true") } return nil } return fmt.Errorf("invalid type, expected bool, got %T", value) }
AssureBoolFalse ensures a boolean value is false. Returns an error if the value is true or not a bool.
var AssureBoolTrue = func(value interface{}) error { if v, ok := value.(bool); ok { if !v { return fmt.Errorf("value must be true, got false") } return nil } return fmt.Errorf("invalid type, expected bool, got %T", value) }
AssureBoolTrue ensures a boolean value is true. Returns an error if the value is false or not a bool.
var AssureDurationGreaterThan = func(above time.Duration) ValidatorFunc { return func(value interface{}) error { var t time.Duration if v, ok := value.(time.Duration); ok { t = v } if v, ok := value.(*time.Duration); ok { t = *v } if t < above { return fmt.Errorf("value must be above %v, got = %v", above, t) } return nil } }
AssureDurationGreaterThan ensures a time.Duration is greater than (but not including) a time.Duration. Returns an error if the value is below, or not an int.
var AssureDurationLessThan = func(below time.Duration) ValidatorFunc { return func(value interface{}) error { var t time.Duration if v, ok := value.(time.Duration); ok { t = v } if v, ok := value.(*time.Duration); ok { t = *v } if t > below { return fmt.Errorf("value must be below %v, got = %v", below, t) } return nil } }
AssureDurationLessThan ensures a time.Duration is less than (but not including) a time.Duration. Returns an error if the value is below, or not an int.
var AssureDurationMax = func(max time.Duration) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(time.Duration); ok { if v > max { return fmt.Errorf("duration must not exceed %s, got %s", max, v) } return nil } return fmt.Errorf("invalid type, expected time.Duration, got %T", value) } }
AssureDurationMax ensures a time.Duration does not exceed a maximum value. Returns an error if the value exceeds the max or is not a time.Duration.
var AssureDurationMin = func(min time.Duration) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(time.Duration); ok { if v < min { return fmt.Errorf("duration must be at least %s, got %s", min, v) } return nil } return fmt.Errorf("invalid type, expected time.Duration, got %T", value) } }
AssureDurationMin ensures a time.Duration is at least a minimum value. Returns a ValidatorFunc that checks the duration against the minimum.
var AssureDurationPositive = func(value interface{}) error { if v, ok := value.(time.Duration); ok { if v <= 0 { return fmt.Errorf("duration must be positive, got %s", v) } return nil } return fmt.Errorf("invalid type, expected time.Duration, got %T", value) }
AssureDurationPositive ensures a time.Duration is positive. Returns an error if the value is zero or negative, or not a time.Duration.
var AssureFloat64GreaterThan = func(above float64) ValidatorFunc { return func(value interface{}) error { if v, err := toFloat64(value); err == nil { if v < above { return fmt.Errorf("value must be below %f", v) } return nil } else { return err } } }
AssureFloat64GreaterThan ensures an integer is greater than (but not including) an int. Returns an error if the value is below, or not an int.
var AssureFloat64InRange = func(min, max float64) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(float64); ok { if v < min || v > max { return fmt.Errorf("value must be between %f and %f, got %f", min, max, v) } return nil } return fmt.Errorf("invalid type, expected float64, got %T", value) } }
AssureFloat64InRange ensures a float64 is within a specified range (inclusive). Returns an error if the value is outside the range or not a float64.
var AssureFloat64LessThan = func(below float64) ValidatorFunc { return func(value interface{}) error { if v, err := toFloat64(value); err == nil { if v > below { return fmt.Errorf("value must be below %f", v) } return nil } else { return err } } }
AssureFloat64LessThan ensures an integer is less than (but not including) an int. Returns an error if the value is above, or not an int.
var AssureFloat64NotNaN = func(value interface{}) error { if v, ok := value.(float64); ok { if math.IsNaN(v) { return fmt.Errorf("value must not be NaN, got %f", v) } return nil } return fmt.Errorf("invalid type, expected float64, got %T", value) }
AssureFloat64NotNaN ensures a float64 is not NaN. Returns an error if the value is NaN or not a float64.
var AssureFloat64Positive = func(value interface{}) error { if v, ok := value.(float64); ok { if v <= 0 { return fmt.Errorf("value must be positive, got %f", v) } return nil } return fmt.Errorf("invalid type, expected float64, got %T", value) }
AssureFloat64Positive ensures a float64 is positive. Returns an error if the value is zero or negative, or not a float64.
var AssureInt64GreaterThan = func(above int64) ValidatorFunc { return func(value interface{}) error { if v, err := toInt64(value); err == nil { if v < above { return fmt.Errorf("value must be below %d", v) } return nil } else { return err } } }
AssureInt64GreaterThan ensures an integer is greater than (but not including) an int. Returns an error if the value is below, or not an int.
var AssureInt64InRange = func(min, max int64) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(int64); ok { if v < min || v > max { return fmt.Errorf("value must be between %d and %d, got %d", min, max, v) } return nil } return fmt.Errorf("invalid type, expected int64, got %T", value) } }
AssureInt64InRange ensures an int64 is within a specified range (inclusive). Returns a ValidatorFunc that checks the value against min and max.
var AssureInt64LessThan = func(below int64) ValidatorFunc { return func(value interface{}) error { if v, err := toInt64(value); err == nil { if v > below { return fmt.Errorf("value must be below %d", v) } return nil } else { return err } } }
AssureInt64LessThan ensures an integer is less than (but not including) an int. Returns an error if the value is above, or not an int.
var AssureInt64Positive = func(value interface{}) error { if v, ok := value.(int64); ok { if v <= 0 { return fmt.Errorf("value must be positive, got %d", v) } return nil } return fmt.Errorf("invalid type, expected int64, got %T", value) }
AssureInt64Positive ensures an int64 is positive. Returns an error if the value is zero or negative, or not an int64.
var AssureIntGreaterThan = func(above int) ValidatorFunc { return func(value interface{}) error { if v, err := toInt(value); err == nil { if v < above { return fmt.Errorf("value must be below %d", v) } return nil } else { return err } } }
AssureIntGreaterThan ensures an integer is greater than (but not including) an int. Returns an error if the value is below, or not an int.
var AssureIntInRange = func(min, max int) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(int); ok { if v < min || v > max { return fmt.Errorf("value must be between %d and %d, got %d", min, max, v) } return nil } return fmt.Errorf("invalid type, expected int, got %T", value) } }
AssureIntInRange ensures an integer is within a specified range (inclusive). Returns an error if the value is outside the range or not an int.
var AssureIntLessThan = func(below int) ValidatorFunc { return func(value interface{}) error { if v, err := toInt(value); err == nil { if v > below { return fmt.Errorf("value must be below %d", v) } return nil } else { return err } } }
AssureIntLessThan ensures an integer is less than (but not including) an int. Returns an error if the value is above, or not an int.
var AssureListContains = func(value string) ValidatorFunc { return func(v interface{}) error { if list, ok := v.(*ListFlag); ok && list != nil { for _, item := range *list.values { if item == value { return nil } } } if list, ok := v.(*[]string); ok && list != nil { for _, item := range *list { if item == value { return nil } } } if list, ok := v.([]string); ok && list != nil { for _, item := range list { if item == value { return nil } } return fmt.Errorf("list must contain %q, got %v", value, list) } return fmt.Errorf("invalid type, expected *ListFlag, []string, or *[]string, got %T", v) } }
AssureListContains ensures a list contains a specific string value. Returns a ValidatorFunc that checks for the presence of the value.
var AssureListContainsKey = func(key string) ValidatorFunc { return func(value interface{}) error { switch list := value.(type) { case *ListFlag: if list == nil { return fmt.Errorf("list is nil") } for _, item := range *list.values { if item == key { return nil } } return fmt.Errorf("list must contain %q, got %v", key, *list.values) case *[]string: if list == nil { return fmt.Errorf("list is nil") } for _, item := range *list { if item == key { return nil } } return fmt.Errorf("list must contain %q, got %v", key, *list) case []string: for _, item := range list { if item == key { return nil } } return fmt.Errorf("list must contain %q, got %v", key, list) default: return fmt.Errorf("invalid type, expected *ListFlag or []string, got %T", value) } } }
AssureListContainsKey ensures a list contains a specific string. It accepts *ListFlag, *[]string, or []string and returns an error if the key string is not found or the type is invalid.
var AssureListLength = func(length int) ValidatorFunc { return func(value interface{}) error { switch list := value.(type) { case *ListFlag: if list == nil { return fmt.Errorf("list is nil") } if len(*list.values) != length { return fmt.Errorf("list must have length %d, got %d", length, len(*list.values)) } return nil case *[]string: if list == nil { return fmt.Errorf("list is nil") } if len(*list) != length { return fmt.Errorf("list must have length %d, got %d", length, len(*list)) } return nil case []string: if len(list) != length { return fmt.Errorf("list must have length %d, got %d", length, len(list)) } return nil default: return fmt.Errorf("invalid type, expected *ListFlag or []string, got %T", value) } } }
AssureListLength ensures a list has exactly the specified length. It accepts *ListFlag, *[]string, or []string and returns an error if the length differs or the type is invalid.
var AssureListMinLength = func(min int) ValidatorFunc { return func(value interface{}) error { switch v := value.(type) { case *ListFlag: if len(*v.values) < min { return fmt.Errorf("list must have at least %d elements, got %d", min, len(*v.values)) } return nil case *[]string: if len(*v) < min { return fmt.Errorf("list is empty") } return nil case []string: if len(v) < min { return fmt.Errorf("list is empty") } return nil default: return fmt.Errorf("invalid type, expected *ListFlag or []string, got %T", v) } } }
AssureListMinLength ensures a list has at least a minimum number of elements. Returns an error if the list is too short or not a ListFlag.
var AssureListNotEmpty = func(value interface{}) error { switch v := value.(type) { case *ListFlag: if v == nil || len(*v.values) == 0 { return fmt.Errorf("list is empty") } return nil case *[]string: if len(*v) == 0 { return fmt.Errorf("list is empty") } return nil case []string: if len(v) == 0 { return fmt.Errorf("list is empty") } return nil default: return fmt.Errorf("invalid type, expected *ListFlag or []string, got %T", v) } }
AssureListNotEmpty ensures a list is not empty. Returns an error if the list has no elements or is not a ListFlag.
var AssureMapHasKey = func(key string) ValidatorFunc { return func(value interface{}) error { switch v := value.(type) { case *MapFlag: if _, exists := (*v.values)[key]; !exists { return fmt.Errorf("map must contain key %q", key) } return nil case *map[string]string: if _, exists := (*v)[key]; !exists { return fmt.Errorf("map must contain key %q", key) } return nil case map[string]string: if _, exists := v[key]; !exists { return fmt.Errorf("map must contain key %q", key) } return nil default: return fmt.Errorf("invalid type, got %T", value) } } }
AssureMapHasKey ensures a map contains a specific key. Returns an error if the key is missing or the value is not a MapFlag.
var AssureMapHasKeys = func(keys []string) ValidatorFunc { return func(value interface{}) error { missing := []string{} switch m := value.(type) { case *MapFlag: if m == nil { return fmt.Errorf("map is nil") } for _, key := range keys { if _, exists := (*m.values)[key]; !exists { missing = append(missing, key) } } case *map[string]string: if m == nil { return fmt.Errorf("map is nil") } for _, key := range keys { if _, exists := (*m)[key]; !exists { missing = append(missing, key) } } case map[string]string: for _, key := range keys { if _, exists := m[key]; !exists { missing = append(missing, key) } } default: return fmt.Errorf("invalid type, expected *MapFlag or map[string]string, got %T", value) } if len(missing) > 0 { return fmt.Errorf("map must contain keys %v, missing %v", keys, missing) } return nil } }
AssureMapHasKeys ensures a map contains all specified keys. Returns an error if any key is missing or the value is not a *MapFlag.
var AssureMapLength = func(length int) ValidatorFunc { return func(value interface{}) error { switch m := value.(type) { case *MapFlag: if m == nil { return fmt.Errorf("map is nil") } if len(*m.values) != length { return fmt.Errorf("map must have length %d, got %d", length, len(*m.values)) } return nil case *map[string]string: if m == nil { return fmt.Errorf("map is nil") } if len(*m) != length { return fmt.Errorf("map must have length %d, got %d", length, len(*m)) } return nil case map[string]string: if len(m) != length { return fmt.Errorf("map must have length %d, got %d", length, len(m)) } return nil default: return fmt.Errorf("invalid type, expected *MapFlag or map[string]string, got %T", value) } } }
AssureMapLength ensures a map has exactly the specified length. It accepts *MapFlag, *map[string]string, or map[string]string and returns an error if the length differs or the type is invalid.
var AssureMapNotEmpty = func(value interface{}) error { switch v := value.(type) { case *MapFlag: if len(*v.values) == 0 { return fmt.Errorf("map is empty") } return nil case *map[string]string: if len(*v) == 0 { return fmt.Errorf("list is empty") } return nil case map[string]string: if len(v) == 0 { return fmt.Errorf("list is empty") } return nil default: return fmt.Errorf("invalid type, expected *ListFlag or []string, got %T", v) } }
AssureMapNotEmpty ensures a map is not empty. Returns an error if the map has no entries or is not a MapFlag.
var AssureMapValueMatches = func(key, value string) ValidatorFunc { return func(v interface{}) error { switch m := v.(type) { case *MapFlag: if val, exists := (*m.values)[key]; exists { if val != value { return fmt.Errorf("map key %q must have value %q, got %q", key, value, val) } return nil } return fmt.Errorf("map key %q does not exist", key) case *map[string]string: if val, exists := (*m)[key]; exists { if val != value { return fmt.Errorf("map value %q must have value %q, got %q", key, value, val) } return nil } return fmt.Errorf("map key %q does not exist", key) case map[string]string: if val, exists := m[key]; exists { if val != value { return fmt.Errorf("map value %q must have value %q, got %q", key, value, val) } return nil } return fmt.Errorf("map key %q does not exist", key) default: return fmt.Errorf("invalid type, expected map[string]string, got %T", v) } } }
AssureMapValueMatches ensures a map has a specific key with a matching value. Returns a ValidatorFunc that checks for the key-value pair.
var AssureNegativeInt = func(value interface{}) error { if v, ok := value.(int); ok { if v >= 0 { return fmt.Errorf("value must be negative, got %d", v) } return nil } return fmt.Errorf("invalid type, expected int, got %T", value) }
AssureNegativeInt ensures an integer is negative. Returns an error if the value is zero or positive, or not an int.
var AssurePositiveInt = func(value interface{}) error { if v, ok := value.(int); ok { if v <= 0 { return fmt.Errorf("value must be positive, got %d", v) } return nil } return fmt.Errorf("invalid type, expected int, got %T", value) }
AssurePositiveInt ensures an integer is positive. Returns an error if the value is zero or negative, or not an int.
var AssureStringContains = func(substring string) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(string); ok { if !strings.Contains(v, substring) { return fmt.Errorf("string must contain %q, got %q", substring, v) } return nil } return fmt.Errorf("invalid type, got %T", value) } }
AssureStringContains ensures a string contains a specific substring. Returns an error if the substring is not found or if the value is not a string.
var AssureStringHasPrefix = func(prefix string) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(string); ok { if !strings.HasPrefix(v, prefix) { return fmt.Errorf("string must have prefix substring %q, got %q", prefix, v) } return nil } return fmt.Errorf("invalid type, expected string, got %T", value) } }
AssureStringHasPrefix ensures a string begins with a prefix Returns a ValidatorFunc that checks for the substring (case-sensitive).
var AssureStringHasSuffix = func(suffix string) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(string); ok { if !strings.HasSuffix(v, suffix) { return fmt.Errorf("string must have suffix substring %q, got %q", suffix, v) } return nil } return fmt.Errorf("invalid type, expected string, got %T", value) } }
AssureStringHasSuffix ensures a string ends with a suffix Returns a ValidatorFunc that checks for the substring (case-sensitive).
var AssureStringLength = func(length int) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(string); ok { if len(v) < length { return fmt.Errorf("string must be at least %d chars, got %q", length, len(v)) } return nil } return fmt.Errorf("invalid type, expected string, got %T", value) } }
AssureStringLength ensures a string contains a specific substring. Returns a ValidatorFunc that checks for the substring (case-sensitive).
var AssureStringLengthGreaterThan = func(length int) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(string); ok { if len(v) < length { return fmt.Errorf("string must be greater than %d chars, got %d", length, len(v)) } return nil } return fmt.Errorf("invalid type, expected string, got %T", value) } }
AssureStringLengthGreaterThan ensures the string is greater than an int Returns a ValidatorFunc that checks for the substring (case-sensitive).
var AssureStringLengthLessThan = func(length int) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(string); ok { if len(v) > length { return fmt.Errorf("string must be less than %d chars, got %d", length, len(v)) } return nil } return fmt.Errorf("invalid type, expected string, got %T", value) } }
AssureStringLengthLessThan ensures the string is less than an int Returns a ValidatorFunc that checks for the substring (case-sensitive).
var AssureStringNotEmpty = func(value interface{}) error { if v, ok := value.(string); ok { if len(v) == 0 { return fmt.Errorf("empty string") } return nil } return fmt.Errorf("invalid type, got %T", value) }
AssureStringNotEmpty ensures a string is not empty. Returns an error if the value is an empty string or not a string.
var AssureStringSubstring = func(sub string) ValidatorFunc { return func(value interface{}) error { if v, ok := value.(string); ok { if !strings.Contains(v, sub) { return fmt.Errorf("string must contain substring %q, got %q", sub, v) } return nil } return fmt.Errorf("invalid type, expected string, got %T", value) } }
AssureStringSubstring ensures a string contains a specific substring. Returns a ValidatorFunc that checks for the substring (case-sensitive).
var ConfigFilePath string = filepath.Join(".", DefaultYAMLFile)
ConfigFilePath stores the path to the configuration file of choice
var EnvironmentKey string = "CONFIG_FILE"
EnvironmentKey stores the preferred ENV that contains the path to your configuration file (.ini, .json or .yaml)
var Mutageneses = []Mutagenesis{tString, tBool, tInt, tInt64, tFloat64, tDuration, tUnitDuration, tList, tMap}
Mutageneses is the plural form of Mutagenesis and this is a slice of Mutagenesis
Functions ¶
This section is empty.
Types ¶
type Fig ¶
type Fig struct {
Flesh interface{}
Mutagenesis Mutagenesis
Validator ValidatorFunc
Error error
Mutations []Mutation
}
type Fruit ¶
type Fruit interface {
// WithValidator binds a ValidatorFunc to a Fig that returns Fruit
WithValidator(name string, validator func(interface{}) error) Fruit
// Parse can panic but interprets command line arguments defined with single dashes -example value -another sample
Parse() error
// ParseFile can panic but also can throw an error because it will attempt to load either JSON, YAML or INI file passed into it
ParseFile(filename string) error
// ErrorFor returns an error attached to a named Fig
ErrorFor(name string) error
// Recall allows you to unlock the Tree from changes and resume tracking
Recall()
// Curse allows you to lock the Tree from changes and stop tracking
Curse()
// Mutations receives Mutation data on a receiver channel
Mutations() <-chan Mutation
// Resurrect takes a nil Fig in the Tree.figs map and reloads it from ENV or the config file if available
Resurrect(name string)
// Load can panic but also can throw an error but will use the Environment Variable values if they are "EXAMPLE=value" or "ANOTHER=sample"
Load() error
// LoadFile accepts a path to a JSON, YAML or INI file to set values
LoadFile(path string) error
// Reload will refresh stored values of properties with their new Environment Variable values
Reload() error
// Usage displays the helpful menu of figs registered using -h or -help
Usage() string
// Int returns a pointer to a registered int32 by name as -name=1 a pointer to 1 is returned
Int(name string) *int
// NewInt registers a new int32 flag by name and returns a pointer to the int32 storing the initial value
NewInt(name string, value int, usage string) *int
// Int64 returns a pointer to a registered int64 by name as -name=1 a pointer to 1 is returned
Int64(name string) *int64
// NewInt64 registers a new int32 flag by name and returns a pointer to the int64 storing the initial value
NewInt64(name string, value int64, usage string) *int64
// Float64 returns a pointer to a registered float64 by name as -name=1.0 a pointer to 1.0 is returned
Float64(name string) *float64
// NewFloat64 registers a new float64 flag by name and returns a pointer to the float64 storing the initial value
NewFloat64(name string, value float64, usage string) *float64
// String returns a pointer to stored string by -name=value
String(name string) *string
// NewString registers a new string flag by name and returns a pointer to the string storing the initial value
NewString(name, value, usage string) *string
// Bool returns a pointer to stored bool by -name=true
Bool(name string) *bool
// NewBool registers a new bool flag by name and returns a pointer to the bool storing the initial value
NewBool(name string, value bool, usage string) *bool
// Duration returns a pointer to stored time.Duration (unitless) by name like -minutes=10 (requires multiplication of * time.Minute to match memetics of "minutes" flag name and human interpretation of this)
Duration(name string) *time.Duration
// NewDuration registers a new time.Duration by name and returns a pointer to it storing the initial value
NewDuration(name string, value time.Duration, usage string) *time.Duration
// UnitDuration returns a pointer to stored time.Duration (-name=10 w/ units as time.Minute == 10 minutes time.Duration)
UnitDuration(name string) *time.Duration
// NewUnitDuration registers a new time.Duration by name and returns a pointer to it storing the initial value
NewUnitDuration(name string, value, units time.Duration, usage string) *time.Duration
// List returns a pointer to a []string containing strings
List(name string) *[]string
// NewList registers a new []string that can be assigned -name="ONE,TWO,THREE,FOUR"
NewList(name string, value []string, usage string) *[]string
// Map returns a pointer to a map[string]string containing strings
Map(name string) *map[string]string
// NewMap registers a new map[string]string that can be assigned -name="PROPERTY=VALUE,ANOTHER=VALUE"
NewMap(name string, value map[string]string, usage string) *map[string]string
// StoreInt replaces name with value and can issue a Mutation when receiving on Mutations()
StoreInt(name string, value int) Fruit
// StoreInt64 replaces name with value and can issue a Mutation when receiving on Mutations()
StoreInt64(name string, value int64) Fruit
// StoreFloat64 replaces name with value and can issue a Mutation when receiving on Mutations()
StoreFloat64(name string, value float64) Fruit
// StoreString replaces name with value and can issue a Mutation when receiving on Mutations()
StoreString(name, value string) Fruit
// StoreBool replaces name with value and can issue a Mutation when receiving on Mutations()
StoreBool(name string, value bool) Fruit
// StoreDuration replaces name with value and can issue a Mutation when receiving on Mutations()
StoreDuration(name string, value time.Duration) Fruit
// StoreUnitDuration replaces name with value and can issue a Mutation when receiving on Mutations()
StoreUnitDuration(name string, value, units time.Duration) Fruit
// StoreList replaces name with value and can issue a Mutation when receiving on Mutations()
StoreList(name string, value []string) Fruit
// StoreMap replaces name with value and can issue a Mutation when receiving on Mutations()
StoreMap(name string, value map[string]string) Fruit
}
Fruit defines the interface for configuration management.
func Grow ¶
func Grow() Fruit
Grow is a memetic alias of New Example:
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
figs := figtree.Grow()
go func() {
for {
select {
case <-ctx.Done():
return
case mutation, ok := <-figs.Mutations():
if ok {
log.Println(mutation)
}
}
}
}()
// figs implements figtree.Fruit interface
func New ¶
func New() Fruit
New will initialize the Tree package Usage:
When defining:
figs := figtree.New()
figs.NewInt("workers", 10, "number of workers")
figs.Parse()
OR err := figs.Load()
OR err := figs.ParseFile("path/to/file.json")
THEN workers := *figs.Int("workers") // workers is a regular int
type ListFlag ¶
type ListFlag struct {
// contains filtered or unexported fields
}
ListFlag stores values in a list type configurable
type MapFlag ¶
type MapFlag struct {
// contains filtered or unexported fields
}
MapFlag stores values in a map type configurable
type Mutagenesis ¶
type Mutagenesis string
Mutagenesis stores the type as a string like String, Bool, Float, etc to represent a supported Type
type Options ¶
type Options struct {
ConfigFile string
// Tracking creates a buffered channel that allows you to select { case mutation, ok := <-figs.Mutations(): }
Tracking bool
// Germinate enables the option to filter os.Args that begin with -test. prefix
Germinate bool
// Harvest allows you to set the buffer size of the Mutations channel
Harvest int
// Pollinate will enable Getters to lookup the environment for changes on every read
Pollinate bool
}
Options allow you enable mutation tracking on your figs.Grow
type Tree ¶
type Tree struct {
ConfigFilePath string
// contains filtered or unexported fields
}
Tree stores figs that are defined by their name and Fig as well as a mutations channel and tracking bool for Options.Tracking
func (*Tree) Curse ¶
func (fig *Tree) Curse()
Curse is when you lock the fig *Tree from further changes, stop tracking and close the channel
func (*Tree) Load ¶
Load uses the EnvironmentKey and the DefaultJSONFile, DefaultYAMLFile, and DefaultINIFile to run ParseFile if it exists
func (*Tree) MutagensisOf ¶
func (fig *Tree) MutagensisOf(what interface{}) Mutagenesis
MutagensisOf accepts anything and allows you to determine the Mutagensis of the type of from what
func (*Tree) MutagensisOfFig ¶
func (fig *Tree) MutagensisOfFig(name string) Mutagenesis
MutagensisOfFig returns the Mutagensis of the name
func (*Tree) NewDuration ¶
NewDuration with validator and withered support
func (*Tree) NewFloat64 ¶
NewFloat64 with validator and withered support
func (*Tree) NewUnitDuration ¶
func (fig *Tree) NewUnitDuration(name string, value, units time.Duration, usage string) *time.Duration
NewUnitDuration registers a new time.Duration with a unit time.Duration against a name
func (*Tree) Parse ¶
Parse uses Tree.flagSet to run flag.Parse() on the registered figs and returns nil for validated results
func (*Tree) Recall ¶
func (fig *Tree) Recall()
Recall is when you bring the mutations channel back to life and you unlock making further changes to the fig *Tree
func (*Tree) Resurrect ¶
Resurrect revives a missing or nil definition, checking env and config files first
func (*Tree) StoreBool ¶
StoreBool replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreDuration ¶
StoreDuration replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreFloat64 ¶
StoreFloat64 replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreInt ¶
StoreInt replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreInt64 ¶
StoreInt64 replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreList ¶
StoreList replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreMap ¶
StoreMap replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreString ¶
StoreString replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) StoreUnitDuration ¶
StoreUnitDuration replaces the name with the new value while issuing a Mutation if Tree.tracking is true
func (*Tree) UnitDuration ¶
UnitDuration with mutation tracking
type ValidatorFunc ¶
type ValidatorFunc func(interface{}) error
