Documentation ¶
Overview ¶
Package oprions provides a way to define and manage options for application components.
Index ¶
- Variables
- func MergeOptions(dest, src *Options) error
- type Arg
- type Kind
- type Option
- type OptionSpec
- type Options
- func (opts *Options) Accepts(key string) bool
- func (opts *Options) Add(spec OptionSpec) error
- func (opts *Options) Describe(key string) string
- func (opts *Options) Get(key string) vars.Variable
- func (opts *Options) Has(key string) bool
- func (opts *Options) Len() int
- func (opts *Options) Load(key string) (vars.Variable, bool)
- func (opts *Options) Name() string
- func (opts *Options) Range(fn func(opt Option) bool)
- func (opts *Options) Seal() error
- func (opts *Options) Set(key string, value any) error
- func (opts *Options) WithPrefix(prefix string) *vars.Map
- type ValueValidator
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrOption = errors.New("option error") ErrOptionReadOnly = fmt.Errorf("%w: readonly option", ErrOption) ErrOptionValidation = fmt.Errorf("%w: validation failed", ErrOption) )
Noopvalidator provides no validation for option value.
Functions ¶
func MergeOptions ¶
Types ¶
type Arg ¶
type Arg struct {
// contains filtered or unexported fields
}
type OptionSpec ¶
type OptionSpec struct {
// contains filtered or unexported fields
}
OptionSpec holds specification for given option.
func NewOption ¶
func NewOption(key string, dval any, desc string, kind Kind, vfunc ValueValidator) OptionSpec
Option returns new option specificationwith given key, value, description and validator.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options is general collection of options attached to specific application component.
func New ¶
func New(name string, specs []OptionSpec) (*Options, error)
New returns new named options set.
func (*Options) Add ¶
func (opts *Options) Add(spec OptionSpec) error
type ValueValidator ¶
OptionValueValidator is callback function to validate given value, it recieves copy of value for validation. It MUST return error if validation fails, returned boolean indicates shoulkd that option be marked as radonly if validation succeeds.
Click to show internal directories.
Click to hide internal directories.