Documentation
¶
Index ¶
- Constants
- Variables
- func DeduplicateStrings(slice []string) []string
- func ParseCustomDuration(input string) (time.Duration, error)
- func Version() string
- type Callback
- type CallbackFunc
- type CallbackWhen
- type Core
- type CoreAbilities
- type CoreMutations
- type Divine
- type Durable
- type ErrConversion
- type ErrInvalidType
- type ErrInvalidValue
- type ErrLoadFailure
- type ErrValidationFailure
- type ErrValue
- type FigValidatorFunc
- type Flaggable
- type Flesh
- type Floatable
- type Intable
- type Intable64
- type ListFlag
- type Listable
- type Loadable
- type MapFlag
- type Mappable
- type Mutable
- type Mutagenesis
- type Mutation
- type Options
- type Parsable
- type Plant
- type Readable
- type RuleKind
- type Savable
- type String
- type Value
- type Withables
Constants ¶
const ( ErrWayBeBelow string = "be below" ErrWayBeAbove string = "be above" ErrWayBeBetweenFmt string = "be between %v and %v" ErrWayBePositive string = "be positive" ErrWayBeNegative string = "be negative" ErrWayBeNotNaN string = "not be NaN" )
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 CallbackAfterChange CallbackWhen = "CallbackAfterChange" CallbackAfterRead CallbackWhen = "CallbackAfterRead" CallbackAfterVerify CallbackWhen = "CallbackAfterVerify" CallbackBeforeChange CallbackWhen = "CallbackBeforeChange" CallbackBeforeRead CallbackWhen = "CallbackBeforeRead" CallbackBeforeVerify CallbackWhen = "CallbackBeforeVerify" )
Variables ¶
var AssureBoolFalse = func(value interface{}) error { v := figFlesh{value, nil} if v.IsBool() { if v.ToBool() { return fmt.Errorf("value must be false, got true") } return nil } return ErrInvalidType{tBool, 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 { v := figFlesh{value, nil} if v.IsBool() { if !v.ToBool() { return fmt.Errorf("value must be true, got false") } return nil } return ErrInvalidType{tBool, 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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsDuration() { return fmt.Errorf("value must be a duration, got %v", value) } t := v.ToDuration() if t < above { return ErrValue{ErrWayBeAbove, t, above} } 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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsDuration() { return fmt.Errorf("value must be a duration, got %v", value) } t := v.ToDuration() if t > below { return ErrValue{ErrWayBeBelow, t, below} } 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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsDuration() { return ErrInvalidType{tDuration, value} } d := v.ToDuration() if d > max { return fmt.Errorf("duration must not exceed %s, got %s", max, d) } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsDuration() { return ErrInvalidType{tDuration, value} } d := v.ToDuration() if d < min { return fmt.Errorf("duration must be at least %s, got %s", min, d) } return nil } }
AssureDurationMin ensures a time.Duration is at least a minimum value. Returns a figValidatorFunc that checks the duration against the minimum.
var AssureDurationPositive = func(value interface{}) error { v := figFlesh{value, nil} if !v.IsDuration() { return ErrInvalidType{tDuration, value} } d := v.ToDuration() if d <= 0 { return fmt.Errorf("duration must be positive, got %s", d) } return nil }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsFloat64() { return ErrInvalidType{tFloat64, value} } f := v.ToFloat64() if f < above { return ErrValue{ErrWayBeBelow, f, above} } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsFloat64() { return ErrInvalidType{tFloat64, value} } f := v.ToFloat64() if f < min || f > max { return ErrValue{fmt.Sprintf(ErrWayBeBetweenFmt, min, max), f, nil} } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsFloat64() { return ErrInvalidType{tFloat64, value} } f := v.ToFloat64() if f > below { return ErrValue{ErrWayBeBelow, f, below} } return nil } }
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 { v := figFlesh{value, nil} if !v.IsFloat64() { return ErrInvalidType{tFloat64, value} } n := v.ToFloat64() if math.IsNaN(n) { return ErrValue{ErrWayBeNotNaN, n, nil} } return nil }
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 { v := figFlesh{value, nil} if !v.IsFloat64() { return ErrInvalidType{tFloat64, value} } f := v.ToFloat64() if f <= 0 { return ErrValue{ErrWayBePositive, f, 0} } return nil }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsInt64() { return ErrInvalidType{tInt64, value} } i := v.ToInt64() if i < above { return ErrValue{ErrWayBeAbove, i, above} } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsInt64() { return ErrInvalidType{tInt64, value} } i := v.ToInt64() if i < min || i > max { return ErrValue{fmt.Sprintf(ErrWayBeBetweenFmt, min, max), i, nil} } return nil } }
AssureInt64InRange ensures an int64 is within a specified range (inclusive). Returns a figValidatorFunc that checks the value against min and max.
var AssureInt64LessThan = func(below int64) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsInt64() { return fmt.Errorf("value must be int64, got %d", value) } i := v.ToInt64() if i > below { return ErrValue{ErrWayBeBelow, i, below} } return nil } }
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 { v := figFlesh{value, nil} if !v.IsInt64() { return ErrInvalidType{tInt64, value} } i := v.ToInt64() if i <= 0 { return ErrValue{ErrWayBePositive, i, 0} } return nil }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsInt() { return ErrInvalidType{tInt, value} } i := v.ToInt() if i < above { return ErrValue{ErrWayBeBelow, i, above} } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsInt() { return ErrInvalidType{tInt, value} } i := v.ToInt() if i < min || i > max { return ErrValue{fmt.Sprintf(ErrWayBeBetweenFmt, min, max), i, nil} } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsInt() { return ErrInvalidType{tInt, value} } i := v.ToInt() if i > below { return ErrValue{ErrWayBeBelow, i, below} } return nil } }
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 AssureIntNegative = func(value interface{}) error { v := figFlesh{value, nil} if v.IsInt() { if v.ToInt() > 0 { return ErrValue{ErrWayBeNegative, v.ToInt(), 0} } return nil } return ErrInvalidType{tInt, value} }
AssureIntNegative ensures an integer is negative. Returns an error if the value is zero or positive, or not an int.
var AssureIntPositive = func(value interface{}) error { v := figFlesh{value, nil} if v.IsInt() { if v.ToInt() < 0 { return ErrValue{ErrWayBePositive, v.ToInt(), 0} } return nil } return ErrInvalidType{tInt, value} }
AssureIntPositive ensures an integer is positive. Returns an error if the value is zero or negative, or not an int.
var AssureListContains = func(inside string) FigValidatorFunc { return func(value interface{}) error { v := NewFlesh(value) if !v.IsList() { return ErrInvalidType{tList, value} } l := v.ToList() for _, item := range l { if item == inside { return nil } } return fmt.Errorf("list must contain %q, got %v", inside, l) } }
AssureListContains ensures a list contains a specific string value. Returns a figValidatorFunc that checks for the presence of the value.
var AssureListContainsKey = func(key string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsList() { return ErrInvalidType{tList, value} } l := v.ToList() for _, item := range l { if item == key { return nil } } return fmt.Errorf("list must contain %q, got %v", key, l) } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsList() { return ErrInvalidType{tList, value} } l := v.ToList() if len(l) != length { return fmt.Errorf("list must have length %d, got %d", length, len(l)) } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsList() { return ErrInvalidType{tList, value} } l := v.ToList() if len(l) < min { return fmt.Errorf("list is empty") } return nil } }
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 AssureListNotContains = func(not string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsList() { return ErrInvalidType{tList, value} } l := v.ToList() for _, item := range l { if item == not { return fmt.Errorf("list cannot contain %s", item) } } return nil } }
AssureListNotContains ensures a list contains a specific string value. Returns a figValidatorFunc that checks for the presence of the value.
var AssureListNotEmpty = func(value interface{}) error { v := figFlesh{value, nil} if !v.IsList() { return ErrInvalidType{tList, value} } l := v.ToList() if len(l) == 0 { return fmt.Errorf("list is empty") } return nil }
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) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsMap() { return ErrInvalidType{tMap, value} } m := v.ToMap() if _, exists := m[key]; !exists { return fmt.Errorf("map must contain key %q", key) } return nil } }
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) FigValidatorFunc { return func(value interface{}) error { var missing []string v := figFlesh{value, nil} if !v.IsMap() { return ErrInvalidType{tMap, value} } m := v.ToMap() for _, key := range keys { if _, exists := m[key]; !exists { missing = append(missing, key) } } 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 AssureMapHasNoKey = func(key string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsMap() { return ErrInvalidType{tMap, value} } m := v.ToMap() if _, exists := m[key]; exists { return fmt.Errorf("map must not contain key %q", key) } return nil } }
AssureMapHasNoKey ensures a map contains a specific key. Returns an error if the key is missing or the value is not a MapFlag.
var AssureMapLength = func(length int) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsMap() { return ErrInvalidType{tMap, value} } m := v.ToMap() if len(m) != length { return fmt.Errorf("map must have length %d, got %d", length, len(m)) } return nil } }
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 { v := figFlesh{value, nil} if !v.IsMap() { return ErrInvalidType{tMap, value} } m := v.ToMap() if len(m) == 0 { return fmt.Errorf("map is empty") } return nil }
AssureMapNotEmpty ensures a map is not empty. Returns an error if the map has no entries or is not a MapFlag.
var AssureMapNotLength = func(length int) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsMap() { return ErrInvalidType{tMap, value} } m := v.ToMap() if len(m) == length { return fmt.Errorf("map must not have length %d, got %d", length, len(m)) } return nil } }
AssureMapNotLength 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 AssureMapValueMatches = func(key, match string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if !v.IsMap() { return fmt.Errorf("%s is not a map", key) } m := v.ToMap() if val, exists := m[key]; exists { if val != match { return fmt.Errorf("map value %q must have value %q, got %q", key, match, val) } return nil } return fmt.Errorf("map key %q does not exist", key) } }
AssureMapValueMatches ensures a map has a specific key with a matching value. Returns a figValidatorFunc that checks for the key-value pair.
var AssureStringContains = func(substring string) FigValidatorFunc { return makeStringValidator( func(s string) bool { return strings.Contains(s, substring) }, "string must contain %q, got %q", ) }
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) FigValidatorFunc { return makeStringValidator( func(s string) bool { return strings.HasPrefix(s, prefix) }, "string must have prefix %q, got %q", ) }
AssureStringHasPrefix ensures a string starts with the given prefix.
var AssureStringHasPrefixes = func(prefixes []string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { for _, prefix := range prefixes { if !strings.HasPrefix(v.ToString(), prefix) { return fmt.Errorf("string must have prefix %q, got %q", prefix, v) } } return nil } return ErrInvalidType{tString, value} } }
AssureStringHasPrefixes ensures a string begins with a prefix Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringHasSuffix = func(suffix string) FigValidatorFunc { return makeStringValidator( func(s string) bool { return strings.HasSuffix(s, suffix) }, "string must have suffix %q, got %q", ) }
AssureStringHasSuffix ensures a string ends with the given suffix.
var AssureStringHasSuffixes = func(suffixes []string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { for _, suffix := range suffixes { if !strings.HasSuffix(v.ToString(), suffix) { return fmt.Errorf("string must have suffix %q, got %q", suffix, v) } } return nil } return ErrInvalidType{tString, value} } }
AssureStringHasSuffixes ensures a string ends with a suffix Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringLength = func(length int) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if len(vs) < length { return fmt.Errorf("string must be at least %d chars, got %q", length, len(vs)) } return nil } return ErrInvalidType{tString, value} } }
AssureStringLength ensures a string contains a specific substring. Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringLengthGreaterThan = func(length int) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if len(vs) < length { return fmt.Errorf("string must be greater than %d chars, got %d", length, len(vs)) } return nil } return ErrInvalidType{tString, value} } }
AssureStringLengthGreaterThan ensures the string is greater than an int Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringLengthLessThan = func(length int) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if len(vs) > length { return fmt.Errorf("string must be less than %d chars, got %d", length, len(vs)) } return nil } return ErrInvalidType{tString, value} } }
AssureStringLengthLessThan ensures the string is less than an int Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringNoPrefix = func(prefix string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if strings.HasPrefix(vs, prefix) { return fmt.Errorf("string must not have prefix substring %q, got %q", prefix, vs) } return nil } return ErrInvalidType{tString, value} } }
AssureStringNoPrefix ensures a string begins with a prefix Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringNoPrefixes = func(prefixes []string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { for _, prefix := range prefixes { if strings.HasPrefix(v.ToString(), prefix) { return fmt.Errorf("string must not have prefix %q, got %q", prefix, v) } } return nil } return ErrInvalidType{tString, value} } }
AssureStringNoPrefixes ensures a string begins with a prefix Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringNoSuffix = func(suffix string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if strings.HasSuffix(vs, suffix) { return fmt.Errorf("string must not have suffix substring %q, got %q", suffix, vs) } return nil } return ErrInvalidType{tString, value} } }
AssureStringNoSuffix ensures a string ends with a suffix Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringNoSuffixes = func(suffixes []string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { for _, suffix := range suffixes { if strings.HasSuffix(v.ToString(), suffix) { return fmt.Errorf("string must not have suffix substring %q, got %q", suffix, v) } } return nil } return ErrInvalidType{tString, value} } }
AssureStringNoSuffixes ensures a string ends with a suffix Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringNotContains = func(substring string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if strings.Contains(vs, substring) { return fmt.Errorf("string must not contain %q, got %q", substring, vs) } return nil } return ErrInvalidType{tString, value} } }
AssureStringNotContains 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 AssureStringNotEmpty = func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { if len(v.ToString()) == 0 { return fmt.Errorf("empty string") } return nil } return ErrInvalidType{tString, value} }
AssureStringNotEmpty ensures a string is not empty. Returns an error if the value is an empty string or not a string.
var AssureStringNotLength = func(length int) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if len(vs) == length { return fmt.Errorf("string must not be %d chars, got %q", length, len(vs)) } return nil } return ErrInvalidType{tString, value} } }
AssureStringNotLength ensures a string contains a specific substring. Returns a figValidatorFunc that checks for the substring (case-sensitive).
var AssureStringSubstring = func(sub string) FigValidatorFunc { return func(value interface{}) error { v := figFlesh{value, nil} if v.IsString() { vs := v.ToString() if !strings.Contains(vs, sub) { return fmt.Errorf("string must contain substring %q, got %q", sub, vs) } return nil } return ErrInvalidType{tString, value} } }
AssureStringSubstring ensures a string contains a specific substring. Returns a figValidatorFunc 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 ListSeparator = ","
var MapKeySeparator = "="
var MapSeparator = ","
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
var PolicyListAppend bool = false
PolicyListAppend will apply ListFlag.Set to the list of values and not append to any existing values in the ListFlag
var PolicyMapAppend = false
Functions ¶
func DeduplicateStrings ¶ added in v2.0.11
func ParseCustomDuration ¶ added in v2.0.11
Types ¶
type Callback ¶
type Callback struct {
CallbackWhen CallbackWhen
CallbackFunc CallbackFunc
}
type CallbackFunc ¶
type CallbackFunc func(interface{}) error
type CallbackWhen ¶ added in v2.0.4
type CallbackWhen string
type CoreAbilities ¶ added in v2.0.9
type CoreMutations ¶ added in v2.0.9
type Divine ¶ added in v2.0.9
type Divine interface {
// Recall allows you to unlock the figTree from changes and resume tracking
Recall()
// Curse allows you to lock the figTree from changes and stop tracking
Curse()
}
type Durable ¶ added in v2.0.9
type Durable interface {
// 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) Plant
// StoreDuration replaces name with value and can issue a Mutation when receiving on Mutations()
StoreDuration(name string, value time.Duration) Plant
// 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) Plant
// StoreUnitDuration replaces name with value and can issue a Mutation when receiving on Mutations()
StoreUnitDuration(name string, value, units time.Duration) Plant
}
type ErrConversion ¶ added in v2.0.13
type ErrConversion struct {
From Mutagenesis
To Mutagenesis
Got any
}
func (ErrConversion) Error ¶ added in v2.0.13
func (e ErrConversion) Error() string
type ErrInvalidType ¶ added in v2.0.13
type ErrInvalidType struct {
Wanted Mutagenesis
Got any
}
func (ErrInvalidType) Error ¶ added in v2.0.13
func (e ErrInvalidType) Error() string
type ErrInvalidValue ¶ added in v2.0.13
func (ErrInvalidValue) Error ¶ added in v2.0.13
func (e ErrInvalidValue) Error() string
func (ErrInvalidValue) Unwrap ¶ added in v2.0.13
func (e ErrInvalidValue) Unwrap() error
type ErrLoadFailure ¶ added in v2.0.14
func (ErrLoadFailure) Error ¶ added in v2.0.14
func (e ErrLoadFailure) Error() string
func (ErrLoadFailure) Unwrap ¶ added in v2.0.14
func (e ErrLoadFailure) Unwrap() error
type ErrValidationFailure ¶ added in v2.0.14
type ErrValidationFailure struct {
Err error
}
func (ErrValidationFailure) Error ¶ added in v2.0.14
func (e ErrValidationFailure) Error() string
func (ErrValidationFailure) Unwrap ¶ added in v2.0.14
func (e ErrValidationFailure) Unwrap() error
type FigValidatorFunc ¶ added in v2.0.4
type FigValidatorFunc func(interface{}) error
type Flaggable ¶ added in v2.0.9
type Flaggable interface {
// 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) Plant
// StoreBool replaces name with value and can issue a Mutation when receiving on Mutations()
StoreBool(name string, value bool) Plant
}
type Flesh ¶ added in v2.0.4
type Flesh interface {
Is(mutagenesis Mutagenesis) bool
AsIs() interface{}
IsString() bool
IsInt() bool
IsInt64() bool
IsBool() bool
IsFloat64() bool
IsDuration() bool
IsUnitDuration() bool
IsList() bool
IsMap() bool
ToString() string
ToInt() int
ToInt64() int64
ToBool() bool
ToFloat64() float64
ToDuration() time.Duration
ToUnitDuration() time.Duration
ToList() []string
ToMap() map[string]string
}
type Floatable ¶ added in v2.0.9
type Floatable interface {
// 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) Plant
// StoreFloat64 replaces name with value and can issue a Mutation when receiving on Mutations()
StoreFloat64(name string, value float64) Plant
}
type Intable ¶ added in v2.0.9
type Intable interface {
// 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) Plant
// StoreInt replaces name with value and can issue a Mutation when receiving on Mutations()
StoreInt(name string, value int) Plant
}
type Intable64 ¶ added in v2.0.9
type Intable64 interface {
// 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) Plant
// StoreInt64 replaces name with value and can issue a Mutation when receiving on Mutations()
StoreInt64(name string, value int64) Plant
}
type ListFlag ¶
type ListFlag struct {
// contains filtered or unexported fields
}
ListFlag stores values in a list type configurable
func (*ListFlag) Set ¶
Set unpacks a comma separated value argument and appends items to the list of []string
type Listable ¶ added in v2.0.9
type Listable interface {
// 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) Plant
// StoreList replaces name with value and can issue a Mutation when receiving on Mutations()
StoreList(name string, value []string) Plant
}
type Loadable ¶ added in v2.0.9
type Loadable interface {
// 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
}
type MapFlag ¶
type MapFlag struct {
// contains filtered or unexported fields
}
MapFlag stores values in a map type configurable
type Mappable ¶ added in v2.0.9
type Mappable interface {
// 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) Plant
// MapKeys returns the keys of the map[string]string as a []string
MapKeys(name string) []string
// StoreMap replaces name with value and can issue a Mutation when receiving on Mutations()
StoreMap(name string, value map[string]string) Plant
}
type Mutable ¶ added in v2.0.9
type Mutable interface {
// Mutations receives Mutation data on a receiver channel
Mutations() <-chan Mutation
// MutagenesisOfFig will look up a Fruit by name and return the Metagenesis of it
MutagenesisOfFig(name string) Mutagenesis
// MutagenesisOf takes anything and returns the Mutagenesis of it
MutagenesisOf(what interface{}) Mutagenesis
}
type Mutagenesis ¶
type Mutagenesis string
Mutagenesis stores the type as a string like String, Bool, Float, etc to represent a supported Type
func MutagenesisOf ¶ added in v2.0.13
func MutagenesisOf(what interface{}) Mutagenesis
func (Mutagenesis) Kind ¶ added in v2.0.13
func (m Mutagenesis) Kind() string
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
// IgnoreEnvironment is a part of free will, it lets us disregard our environment (ENV vars)
IgnoreEnvironment bool
}
Options allow you enable mutation tracking on your figs.Grow
type Parsable ¶ added in v2.0.9
type Parsable interface {
// 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
}
type Plant ¶ added in v2.0.4
type Plant interface {
Core
CoreAbilities
CoreMutations
}
Plant defines the interface for configuration management.
func Grow ¶
func Grow() Plant
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.Plant interface
func New ¶
func New() Plant
New will initialize the figTree 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
func With ¶
With creates a new fig figTree with predefined Options
Example:
figs := With(Options{
ConfigFilePath: "/opt/app/production.config.yaml",
Pollinate: true,
Tracking: true,
Harvest: 369,
})
// define your figs.New<Mutagenesis>() here...
figs.NewString("domain", "", "Domain name")
figs.WithValidator("domain", figtree.AssureStringNotEmpty)
err := figs.Load()
domainInProductionConfigYamlFile := *figs.String("domain")
type RuleKind ¶ added in v2.0.4
type RuleKind int
const ( RuleUndefined RuleKind = iota // RuleUndefined is default and does no action RulePreventChange RuleKind = iota // RulePreventChange blocks Mutagensis Store methods RulePanicOnChange RuleKind = iota // RulePanicOnChange will throw a panic on the Mutagenesis Store methods RuleNoValidations RuleKind = iota // RuleNoValidations will skip over all WithValidator assignments RuleNoCallbacks RuleKind = iota // RuleNoCallbacks will skip over all WithCallback assignments RuleCondemnedFromResurrection RuleKind = iota // RuleCondemnedFromResurrection will panic if there is an attempt to resurrect a condemned fig RuleNoMaps RuleKind = iota // RuleNoMaps blocks NewMap, StoreMap, and Map from being called on the Tree RuleNoLists RuleKind = iota // RuleNoLists blocks NewList, StoreList, and List from being called on the Tree RuleNoFlags RuleKind = iota // RuleNoFlags disables the flag package from the Tree RuleNoEnv RuleKind = iota // RuleNoEnv skips over all os.Getenv related logic )
type String ¶ added in v2.0.9
type String interface {
// 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) Plant
// StoreString replaces name with value and can issue a Mutation when receiving on Mutations()
StoreString(name, value string) Plant
}
type Value ¶ added in v2.0.11
type Value struct {
Value interface{}
Mutagensis Mutagenesis
Err error
}
func (*Value) IsBoolFlag ¶ added in v2.0.14
type Withables ¶ added in v2.0.9
type Withables interface {
// WithCallback registers a new CallbackWhen with a CallbackFunc on a figFruit on the figTree by its name
WithCallback(name string, whenCallback CallbackWhen, runThis CallbackFunc) Plant
// WithAlias registers a short form of the name of a figFruit on the figTree
WithAlias(name, alias string) Plant
// WithRule attaches a RuleKind to a figFruit
WithRule(name string, rule RuleKind) Plant
// WithTreeRule assigns a global rule on the Tree
WithTreeRule(rule RuleKind) Plant
// WithValidator binds a figValidatorFunc to a figFruit that returns Plant
WithValidator(name string, validator func(interface{}) error) Plant
}
