Documentation ¶
Index ¶
- Constants
- func EnvFieldSubstitution(somestruct interface{}, opts *EnvFieldSubstOpts) (ret []string, err error)
- func EnvFieldSubstitutionFromMap(somestruct interface{}, opts *EnvFieldSubstOpts, m map[string]string) (ret []string, err error)
- func EnvToMap() map[string]string
- func FinalizeFlags(tags *ProcessedFlagTags) (err error)
- func PreProcessFlagsWithFlagSet(somestruct interface{}, set *flag.FlagSet) (err error)
- func Process(opts *ConfTagOpts, somestruct interface{}) (err error)
- func ProcessFlags(somestruct interface{}, opts *FlagFieldSubstOpts) (err error)
- func ProcessFlagsWithFlagSet(somestruct interface{}, set *flag.FlagSet, argz []string) (err error)
- func RegisterDefaultFunc(id string, f DefaultFunc) map[string]DefaultFunc
- func RegisterTestFunc(id string, f TestFunc) map[string]TestFunc
- func RunTestFlags(somestruct interface{}, opts *TestFieldSubstOpts) (ret []string, err error)
- func StringToFloat64(s string) (float64, error)
- func StringToInt64(s string) (int64, error)
- func StringToUint64(s string) (uint64, error)
- func SubsistuteDefaults(somestruct interface{}, opts *DefaultFieldSubstOpts) (ret []string, err error)
- type ConfTagOpts
- type DefaultFieldSubstOpts
- type DefaultFunc
- type EnvFieldSubstOpts
- type FlagFieldSubstOpts
- type ProcessedFlagTags
- type TestFieldSubstOpts
- type TestFunc
- type TestWarnPrintf
Constants ¶
const ( FLAGTAGS int ENVTAGS DEFAULTTAGS TESTTAGS )
const ( NONE int = 0 EQ int = iota // = LT // < GT // > GTE // >- LTE // <= REGEX // ~ TESTFUNC // $(funcname) )
const CONFFIELD = "conf"
const ENVFIELD = "env"
const FLAGFIELD = "flag"
const FLAGFIELDUSAGE = "usage"
Variables ¶
This section is empty.
Functions ¶
func EnvFieldSubstitution ¶
func EnvFieldSubstitution(somestruct interface{}, opts *EnvFieldSubstOpts) (ret []string, err error)
EnvFieldSubstitution is a function that takes a pointer to a struct and looks at each field. If the field has a ENVFIELD tag ("env" by default) then it will look up the value of the field in the environment variables and replace the field with the value. It returns a list of the names of the fields that were substituted - as a list of string If there is an error, it returns an error
func EnvFieldSubstitutionFromMap ¶
func EnvFieldSubstitutionFromMap(somestruct interface{}, opts *EnvFieldSubstOpts, m map[string]string) (ret []string, err error)
EnvFieldSubstitutionFromMap is a function that takes a pointer to a struct
func FinalizeFlags ¶ added in v0.0.4
func FinalizeFlags(tags *ProcessedFlagTags) (err error)
func PreProcessFlagsWithFlagSet ¶ added in v0.0.8
Use this to add in all flags from a given struct *before* flags.Parse() is called anywhere. flags.Parse could be handled by the caller later, OR it may be handled by the conftagz.Process() function.
func Process ¶
func Process(opts *ConfTagOpts, somestruct interface{}) (err error)
func ProcessFlags ¶ added in v0.0.4
func ProcessFlags(somestruct interface{}, opts *FlagFieldSubstOpts) (err error)
This is a convenience function that run the FlagFieldSubstitution and then calls flag.Parse() and then calls FinalizeFlags
func ProcessFlagsWithFlagSet ¶ added in v0.0.4
This is a convenience function that run the FlagFieldSubstitution and then calls flag.Parse() and then calls FinalizeFlags - but with a flag.FlagSet passed in
func RegisterDefaultFunc ¶
func RegisterDefaultFunc(id string, f DefaultFunc) map[string]DefaultFunc
func RunTestFlags ¶
func RunTestFlags(somestruct interface{}, opts *TestFieldSubstOpts) (ret []string, err error)
RUns through all test:"" tags to see if the current value passes the test
func StringToFloat64 ¶
func StringToInt64 ¶
func StringToUint64 ¶ added in v0.0.4
func SubsistuteDefaults ¶
func SubsistuteDefaults(somestruct interface{}, opts *DefaultFieldSubstOpts) (ret []string, err error)
EnvFieldSubstitutionFromMap is a function that takes a pointer to a struct
Types ¶
type ConfTagOpts ¶
type ConfTagOpts struct { OrderOfOps []int EnvOpts *EnvFieldSubstOpts TestOpts *TestFieldSubstOpts DefaultOpts *DefaultFieldSubstOpts FlagTagOpts *FlagFieldSubstOpts }
type DefaultFieldSubstOpts ¶
type DefaultFieldSubstOpts struct { }
type DefaultFunc ¶
type DefaultFunc func(fieldname string) interface{}
type EnvFieldSubstOpts ¶
type EnvFieldSubstOpts struct { // throws an error if the environment variable is not found ThrowErrorIfEnvMissing bool }
type FlagFieldSubstOpts ¶ added in v0.0.4
type FlagFieldSubstOpts struct { // throws an error if the environment variable is not found // ThrowErrorIfEnvMissing bool UseFlags *flag.FlagSet Args []string Tags *ProcessedFlagTags }
type ProcessedFlagTags ¶ added in v0.0.6
type ProcessedFlagTags struct {
// contains filtered or unexported fields
}
func ProcessFlagTags ¶ added in v0.0.6
func ProcessFlagTags(somestruct interface{}, opts *FlagFieldSubstOpts) (ret *ProcessedFlagTags, err error)
func (*ProcessedFlagTags) GetFieldsTouched ¶ added in v0.0.7
func (p *ProcessedFlagTags) GetFieldsTouched() (ret []string)
func (*ProcessedFlagTags) GetFlagsFound ¶ added in v0.0.7
func (p *ProcessedFlagTags) GetFlagsFound() (ret []string)
type TestFieldSubstOpts ¶
type TestFieldSubstOpts struct { // throws an error if the environment variable is not found OnlyWarn bool WarnFunc TestWarnPrintf }
type TestWarnPrintf ¶
type TestWarnPrintf func(format string, args ...interface{})