Documentation
¶
Index ¶
- func Float32OptParser(optValue string) (any, error)
- func Float64OptParser(optValue string) (any, error)
- func GetInterfaceOpt(o Options, whichOpt string) (any, bool)
- func GetOpt[T c.Simple](o Options, whichOpt string, defaultValue T) (T, bool, error)
- func IntOptParser(optValue string) (any, error)
- func StringOptParser(optValue string) (any, error)
- func UintOptParser(optValue string) (any, error)
- type AllowedOptions
- func (ao AllowedOptions) AddCustomOption(optName string, parser OptionParser) AllowedOptions
- func (ao AllowedOptions) AddFloat64Option(optName string) AllowedOptions
- func (ao AllowedOptions) AddIntOption(optName string) AllowedOptions
- func (ao AllowedOptions) AddStringOption(optName string) AllowedOptions
- func (ao AllowedOptions) GetOptionList() []string
- func (ao AllowedOptions) GetParsedOption(optName, optValue string) (any, error)
- func (ao AllowedOptions) ParsePair(pair OptionValuePair) (any, error)
- func (ao AllowedOptions) PopulateOptions(pairs []OptionValuePair, opts Options) error
- type OptionParser
- type OptionValuePair
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float32OptParser ¶
Float32OptParser implements OptionParser specifically translating float32 options.
func Float64OptParser ¶
Float64OptParser implements OptionParser specifically translating float64 options.
func GetInterfaceOpt ¶
GetInterfaceOpt(o, whichOpt) will retrieve the option associated with whichOpt from o. If the value is found, this returns the found value and true, otherwise, this returns nil and false. It is the caller's responsibility to make sure that the option type stored is compatible with the variable to which it is being assigned. Similarly, it is the client responsibility to handle possible default values if the expected value is not found.
func GetOpt ¶
GetOpt(o, whichOpt, defaultValue) will attempt to retrieve the value associated with whichOpt in o. The values returned represent the retrieved (or default) value, whether or not the value was found, and possibly an error if there was a type conversion error. If o does not contain the key whichOpt:
This returns (defaultValue, false, nil)
If o finds a value for whichOpt, but the type does not match the type for defaultValue:
This returns (defaultValue, true, A Non-Nil-Error)
If o find a value "v" for whichOpt, and the value matches the type for defaultValue:
This returns (v, true, nil).
func IntOptParser ¶
IntOptParser implements OptionParser specifically translating int options. It assumes decimal representation of the value.
func StringOptParser ¶
StringOptionParser implements OptionParser specifically translating string options (well, it actually just passes in the string value as-is with no modification, but having this allows us to simply implement the OptionParser interface.
func UintOptParser ¶
UintOptParser implement OptionParser specifically translating uint options. It assumes decimal representation of the value.
Types ¶
type AllowedOptions ¶
type AllowedOptions map[string]OptionParser
AllowedOptions specifies the collection of allowed option kinds, and specifies how to interpret the values. The assumption is that at some point, options are being specified by some kind of key-value pair in a string, such as: "dataWidth:8". In this case, for a given index, if we want to form the desired options, we need to know that:
- "dataWidth" is an allowed option
- how to interpret the string "8".
In this case, to an AllowedOptions type, we would add the key "dataWidth" and an IntParser as the value (or whichever data type is appropriate for the dataWidth option).
func NewAllowedOptions ¶
func NewAllowedOptions() AllowedOptions
func (AllowedOptions) AddCustomOption ¶
func (ao AllowedOptions) AddCustomOption(optName string, parser OptionParser) AllowedOptions
AddCustomOption(optName) will specify that optName is an allowed option, and that the values will be interpreted by the provided parser.
func (AllowedOptions) AddFloat64Option ¶
func (ao AllowedOptions) AddFloat64Option(optName string) AllowedOptions
AddFloat64Option(optName) will specify that optName is an allowed option, and that the values will be interepreted by the standard Float64OptionParser.
func (AllowedOptions) AddIntOption ¶
func (ao AllowedOptions) AddIntOption(optName string) AllowedOptions
AddIntOption(optName) will specify that optName is an allowed option, and that the values will be interepreted by the standard IntOptionParser.
func (AllowedOptions) AddStringOption ¶
func (ao AllowedOptions) AddStringOption(optName string) AllowedOptions
AddStringOption(optName) will specify that optName is an allowed option, and that the values will be interepreted by the standard StringOptionParser.
func (AllowedOptions) GetOptionList ¶
func (ao AllowedOptions) GetOptionList() []string
ao.GetOptionList() provides the list of named options for ao.
func (AllowedOptions) GetParsedOption ¶
func (ao AllowedOptions) GetParsedOption(optName, optValue string) (any, error)
ao.GetParsedOption(optName, optValue) will parse optValue based on the parser associated with optName in ao. Note that if ao does not specify a parser for optName, this will panic!
func (AllowedOptions) ParsePair ¶
func (ao AllowedOptions) ParsePair(pair OptionValuePair) (any, error)
ao.ParsePair(pair) is shorthand for:
ao.GetParsedOption(pair.Option, pair.Value)
func (AllowedOptions) PopulateOptions ¶
func (ao AllowedOptions) PopulateOptions(pairs []OptionValuePair, opts Options) error
ao.PopulateOptions(pairs, opts) will use ao to interpret pairs and use the results to populate opts. This will look at each OptionValuePair in pairs, and if the value can be properly parsed, it will add the result to opts for the given option and result. If one or more of the options cannot be properly interpreted, this results in an error.
type OptionParser ¶
OptionParser translates a string to a value (assuming that the option value is well-formed). See AllowedOptions to see the purpose.
type OptionValuePair ¶
OptionValue pair represents the use of a particular option with a string representation of its intended value. It is expected that one might originally encounter a string representation of the value, but then might need to interpret the intended value for the option.
type Options ¶
An Options instance maps the various named options to their specific values. This is intended as a generic mechanism to specify construction options. Note that the value types can be mixed: i.e., we might store both an int option value and a string option value in the same map.
func NewOptions ¶
func NewOptions() Options
NewOptions() creates a new instance of Options, allowing a client to then modify it to specify whichever packaged options desired.