Documentation ¶
Overview ¶
Package options implements a simple, flexible and convenient method for specifying options, with the help of reflections.
Index ¶
- type Option
- type OptionsProvider
- func (o *OptionsProvider) ExportToMap() map[string]interface{}
- func (o *OptionsProvider) ExportToMapWithTag(tag string) map[string]interface{}
- func (o *OptionsProvider) Get() interface{}
- func (o *OptionsProvider) IsSet(field string) bool
- func (o *OptionsProvider) Options(opts ...Option) *OptionsProvider
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option interface{}
Option represents an option. Each option must be a different struct, and should be defined as a struct with a Value field.
For example:
type RouteName struct { Value: string }
type OptionsProvider ¶
type OptionsProvider struct {
// contains filtered or unexported fields
}
func NewOptions ¶
func NewOptions(spec Spec) *OptionsProvider
NewOptions creates a new OptionsProvider.
func (*OptionsProvider) ExportToMap ¶
func (o *OptionsProvider) ExportToMap() map[string]interface{}
ExportToMap exports the options to a map
func (*OptionsProvider) ExportToMapWithTag ¶
func (o *OptionsProvider) ExportToMapWithTag(tag string) map[string]interface{}
ExportToMapWithTag exports the options to a map, the key names in the map are determined by a specific struct tag. The tags are set in the options spec. Configs that have not been set don't appear in the map.
func (*OptionsProvider) Get ¶
func (o *OptionsProvider) Get() interface{}
Get returns the options data, which could be casted to the original spec type and the value could be get from there.
func (*OptionsProvider) IsSet ¶
func (o *OptionsProvider) IsSet(field string) bool
Check if the field is set
func (*OptionsProvider) Options ¶
func (o *OptionsProvider) Options(opts ...Option) *OptionsProvider
Options set the options in spec according to the opts passed in.
type Spec ¶
type Spec interface{}
Spec specifies the list of options. A spec should be implemented as a struct which have Option fields, each representing an option. Each Option must be a different struct, multiple fields with the same struct type will cause unwanted behavior (only the last field receives the value).