settings

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 14 Imported by: 34

README

Settings - Typed Configuration Toolkit For Go

GoDoc Build Status codecov.io

Status: Incubation

Overview

There aren't very many well tested and maintained libraries in the ecosystem for managing configuration values in a go application. The two that appear with the most prevalence when searching are viper and go-config. Both of these projects provide both dynamic configuration reloading and a broad interface for fetching and converting configuration values. Both of those libraries are fairly stable and excellent choices for configuration if they fit your needs.

This project grew out of a desire for a configuration system that:

  • Allows for the minimum amount of coupling between components needing configuration and the configuration system.

  • Focuses on enabling plugin, or at least swappable component, based systems.

  • Enables developers to define configuration as standard go types rather than as strings in a global, opaque registrar.

  • Provides the ability to remix the basic configuration components to create new complex systems that may differ from our initial assumptions about how we need configuration to work in a given system.

  • Generates useful help output and example configurations from a given set of options.

Honestly, [viper] and [go-config] both come close to satisfying most of these wants but fall short of what we needed in small, but consequential, ways. This project attempts to overcome those small deficits by offering:

  • An extremely minimal interface for defining sources of configuration data so that new or proprietary data sources can be more easily added.

  • A high level API for working with loosely coupled components that describe their configurations with standard go types.

  • A mid level API for defining and managing configuration hierarchies.

  • A low level API for interfacing between statically typed options and weakly typed configuration sources.

Data Sources

All forms of our API interact in some with a source of configuration data. The interface for a source is:

type Source interface {
    Get(ctx context.Context, path []string) (interface{}, error)
}

It is intentionally simple and leaves every implementation detail to the the team creating a new source. Packaged with this project are Source implementations for JSON, YAML, and ENV. We also provide a minimal set of tools for arranging and composing data sources:

jsonSource, _ := settings.NewFileSource("config.json")
yamlSource, _ := settings.NewFileSource("config.yaml")
envSource := settings.NewEnvSource(os.Environ())
// Apply a static prefix to all env lookups. For example,
// here we add a APP_ to all names.
prefixedEnv := &settings.PrefixSource{
    Source: envSource,
    Prefix: []string{"APP"},
}
// Create an ordered lookup where ENV is first with a fallback to
// YAML which can fallback to JSON.  The first found is used.
finalSource := []settings.MultiSource{prefixedEnv, yamlSource, jsonSource}

v, found := finalSource.Get(context.Background(), "setting")

The built-in sources, including MultiSource, support variable substitution, so that you can effectively perform variable mapping. For example, in the following, the final value of B_BB key will be envValue.

config.yaml (be sure to wrap reference values in quotes so the yaml parser interprets it as a string)

b:
  bb: "${A_AA}"

Environment Variable

A_AA="envValue"
yamlSource, _ := settings.NewFileSource("config.yaml")
envSource := settings.NewEnvSource(os.Environ())
finalSource := []settings.MultiSource{yamlSource, envSource}

Recursion protection is such that recursing to a depth of ten will result in the value at the "top" of the recursion stack being returned. For example, the following will return a literal unexpanded value ${b} when getting key a due to infinite recursion protection.

a: "${b}"
b: "${c}"
c: "${a}"

Similarly, the literal value is returned when no expansion is possible. The following will return a literal unexpanded value ${b} when getting key a:

a: "${b}"

Sources may be used as-is by passing them around to components that need to fetch values. However, the values returned from Get() are opaque and highly dependent on the implementation. For example, the ENV source will always return a string representation of the value because that is what is available in the environment. Alternatively, the JSON and YAML sources may return other data types as they typically unmarshal into native go types. Each component fetching values from a source is responsible for safely converting the result into a useful value.

We recommend using one of the API layers we provide to do this for you.

Component API

With one of our goals being the support of plugin based systems, we've built configurable components into the higher level interface of the project. NewComponent is the entry point for the high-level, Component API. This method manages much of the complexity of adding configuration to a system.

func NewComponent(ctx context.Context, s settings.Source, value interface{}, destination interface{}) error

The given context and source are used for all lookups of configuration data. The given value must be an implementation of the component contract and the destination is a pointer created with new(T) where T is the output type (or equivalent convertible) to the element produced by the component contract implementation.

The component contract is an interface that all input values must conform to and is roughly equivalent to the Factory or Constructor concepts. Each instance of the component contract must define two methods: Setting() C and New(context.Context, C) (T, error). Due to the lack of generics in go, there's no way to describe this contract as an actual go interface that would benefit from static typing support. As a result, NewComponent uses reflection to enforce the contract in order to allow for C to be any type that is convertible to configuration via the settings.Convert() method and for T to be any type that your use case requires.

For example, the most minimal implementation of the contract would look like:

// All configuration is driven by a struct that uses standard go types.
type Config struct {}
// The resulting element is virtually anything that you need it to be
// for the purposes of the system you are building.
type Result struct {}
// The component contract interfaces between the thing you want to make,
// the result, and the settings project. It is responsible for producing
// instances of the configuration struct with any default values populated.
// It is also used to construct new instances of the result using a
// populated configuration. No references to the settings project are
// required to create any part of this setup.
type Component struct {}
func (*Component) Settings() *Config { return &Config{} }
func (*Component) New(_ context.Context, c *Config) (*Result, error) {
    return &Result{}, nil
}

From here, any number of settings and sub-trees may be added to Config, any methods or attributes may be added to Result, and any complexity in the creation of Result may be be added to the Component.New method. To then use this basic example as a component you would:

component := &Component{}
r := new(Result)
err := settings.NewComponent(context.Background(), source, component, r)

If the resulting error is nil then the destination value, r in this example, now points to the output of the Component.New method. The method returns an error any time the given component does not satisfy the contract, any time the configuration loading fails, or the Component.New returns an error.

The benefits of using this API are that it is highly flexible with respect to types and it prevents plugins or components from needing to import and using elements from this project. This makes it a bit easier to write tests by removing the need to orchestrate an entire configuration system.

A potential downside to this API is that the resulting configuration hierarchy is not easily modified. The structure is enforced is such that each component receives a top level key and all nested structs result in sub-trees. The name of every setting is generated from the field name and this is not changeable. The description of each field can be set using struct tags. The name and description of each tree may be defined by implementing a Name() and Description() method but the overall arrangement is fixed.

type InnerConfig struct {
    Value2 string `description:"a string"`
}
func (c *InnerConfig) Name() string {
    return "subtree"
}
func (c *InnerConfig) Description() string {
    return "a nesting configuration tree"
}

type OuterConfig struct {
    Value1 int `description:"the first value"`
    InnerConfig *InnerConfig
}
func (c *OuterConfig) Name() string {
    return "toptree"
}
func (c *OuterConfig) Description() string {
    return "the top configuration tree"
}

The above will equate to a configuration like:

toptree:
    value1: 0
    subtree:
        value2: ""

The descriptions are used to annotate example configurations and help output.

Hierarchy API

If the component API is too restrictive for your use case then the Hierarchy API might be of more use. This layer of the API is based on the settings.Setting and settings.Group types which represent individual configuration options and sub-trees, respectively. We include a settings.SettingGroup implementation of the settings.Group which allows you to construct any arbitrary hierarchy of configuration as needed. It also, however, requires coupling the code to this project and using a much more verbose style of defining options:

top := &settings.SettingGroup{
    NameValue: "root",
    GroupValues: []settings.Group{}, // Add any sub-tree here.
    SettingValues: []settings.Setting{ // Add any settings here.
        settings.NewIntSetting("Value1", "an int value", 2),
    },
}

err := settings.LoadGroups(finalSource, []Group{top})

After loading is complete, each Setting value will contain either the given default for a the value found in the Source. This is the same API we used to create the Component API.

Adapter API

If none of the higher API layers provide what you need then we also offer a lower level tool set for creating new high level APIs. At the most basic level, this project contains a large set of strongly types adapters for content pulled from a source. Each adapter is responsible for converting from the empty interface into a native type that the setting exposes. These are named with the pattern of <Type>Setting. We make use of the cast project to handle converting from arbitrary types to target types.

This is the layer to target when adding new supported configuration types or when replacing the type converters with something else. These elements, in possible conjunction with elements from the Hierarchy API, are flexible enough to build anything you need.

Special Type Parsing and Casting

We use the cast library for casting values read in from configurations into their go types. The cast library falls back to JSON for complex types expressed as string values. Here are some examples of how we parse different types:

[]string

For a given configuration

type Config struct {
    TheSlice []string
}

The values in the following examples will all be parsed as a string slice.

yaml

config:
  theslice:
    - "a"
    - "b"
    - "c"

JSON

{"config": {"theslice":  ["a", "b", "c"]}}

You can also set an environment variable and reference them in a YAML or JSON file like below. Note that this environment variable value will be parsed as a slice where each letter will be a value since it gets split by any space in the string.

Environment Variable

CONFIG_THESLICE="a b c"`

yaml

config:
  theslice: "${CONFIG_THESLICE}"

JSON

{"config": {"theslice":  "${CONFIG_THESLICE}"}}

map[string][]string

For a given configuration

type Config struct {
    allowedStrings map[string][]string
}

The values in the following examples will all be parsed as a string map string slices where the key letters and symbols gets included as the string map key and their values are a string slice.

yaml

config:
  allowedStrings:
    letters:
      - "a"
      - "b"
      - "c"
    symbols:
      - "@"
      - "!"

JSON

{
	"config": {
		"allowedStrings": {
			"letters": ["a", "b", "c"],
			"symbols": ["@", "!"]
		}
	}
}

map[string]string

For a given configuration

type Config struct {
    foods map[string]string
}

The values in the following examples will all be parsed as a string map of string values where the key and values get included as the string map key to string values.

yaml

config:
  foods:
    apple: "fruit"
    broccoli: "vegetable"

JSON

{
	"config": {
		"foods": {
			"apple": "fruit",
			"broccoli": "vegetable"
		}
	}
}

time.Time

For a given configuration

type Config struct {
    TheTime time.Time
}

The following examples will be parsed using the RFC3339 format by time.Parse(time.RFC3339, value)

yaml

"config":
  "thetime": "2012-11-01T22:08:41+00:00"

JSON

{"config": {"thetime": "2012-11-01T22:08:41+00:00"}}

Environment Variable

CONFIG_THETIME="2012-11-01T22:08:41+00:00"`

time.Duration

For a given configuration

type Config struct {
	TimeLength time.Duration
}

The following examples will be parsed using time.Duration yaml

"config":
  "timeLength": "4h"

JSON

{"config": {"timeLength": "4h"}}

Environment Variable

CONFIG_TIMELENGTH="4h"

Contributing

License

This project is licensed under Apache 2.0. See LICENSE.txt for details.

Contributing Agreement

Atlassian requires signing a contributor's agreement before we can accept a patch. If you are an individual you can fill out the individual CLA. If you are contributing on behalf of your company then please fill out the corporate CLA.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleEnvGroups

func ExampleEnvGroups(groups []Group) string

ExampleEnvGroups renders a Group to ENV vars.

func ExampleEnvSettings

func ExampleEnvSettings(settings []Setting) string

ExampleEnvSettings renders a collection of settings as ENV vars.

func ExampleYamlGroups

func ExampleYamlGroups(gs []Group) string

ExampleYamlGroups renders a Group to YAML.

func ExampleYamlSettings

func ExampleYamlSettings(settings []Setting) string

ExampleYamlSettings renders a collection of settings as YAML text.

func Load

func Load(ctx context.Context, s Source, settings []Setting) error

Load the values for a given batch of settings using the provided source.

func LoadGroups

func LoadGroups(ctx context.Context, s Source, groups []Group) error

LoadGroups works similarly to Load except that it will operate recursively on all settings and groups in the given group. Each group name will be added as a path segment leading to an individual setting.

func NewComponent

func NewComponent(ctx context.Context, s Source, v interface{}, destination interface{}) error

NewComponent is the entry point for the high-level api. This method manages much of the complexity of adding configuration to a system. The given context and source are used for all lookups of configuration data. The given value is an implementation of the component contract and the destination is a pointer created with new(T) where T is the output type (or equivalent convertible) to the element produced by the component contract implementation.

The component contract is an interface that all input values must conform to and is roughly equivalent to the Factory concept. Each instance of the component contract must define two methods: Setting() C and New(context.Context, C) (T, error). Due to the lack of generics in go, there's no way to describe this contract as an actual go interface that would benefit from static typing support. As a result, this method uses reflect to enforce the contract in order to allow for C to be any type that is convertible to configuration via the Convert() method and for T to be any type that your use case requires.

For example, the most minimal implementation of the contract would look like:

type Config struct {}
type Result struct {}
type Component struct {}
func (*Component) Settings() *Config { return &Config{} }
func (*Component) New(_ context.Context, c *Config) (*Result, error) {
    return &Result{}, nil
}

From here, any number of settings and sub-trees may be added to Config, any methods or attributes may be added to Result, and any complexity in the creation of Result maybe be added to the Component.New method. To then use this basic example as a component you would:

r := new(Result)
err := NewComponent(context.Background(), source, &Component{}, r)

If the resulting error is nil then the destination value, r in this case, now points to the output of the Component.New method. The method returns an error any time the given component does not satisfy the contract, any time the configuration loading fails, or if the Component.New returns an error.

func VerifyComponent

func VerifyComponent(v interface{}) error

VerifyComponent checks if a given value implements the Component contract.

Types

type BaseSetting

type BaseSetting struct {
	NameValue        string
	DescriptionValue string
}

BaseSetting implements the name and description aspects of any given setting.

func (*BaseSetting) Description

func (s *BaseSetting) Description() string

Description returns the human description of a setting for help text.

func (*BaseSetting) Name

func (s *BaseSetting) Name() string

Name returns the setting name as it appears in configuration.

type BoolSetting

type BoolSetting struct {
	*BaseSetting
	BoolValue *bool
}

BoolSetting manages an instance of bool

func NewBoolSetting

func NewBoolSetting(name string, description string, fallback bool) *BoolSetting

NewBoolSetting creates a BoolSetting with the given default value.

func (*BoolSetting) SetValue

func (s *BoolSetting) SetValue(v interface{}) error

SetValue changes the underlying bool.

func (*BoolSetting) Value

func (s *BoolSetting) Value() interface{}

Value returns the underlying bool.

type BoolSliceSetting

type BoolSliceSetting struct {
	*BaseSetting
	BoolSliceValue *[]bool
}

BoolSliceSetting manages an instance of []bool

func NewBoolSliceSetting

func NewBoolSliceSetting(name string, description string, fallback []bool) *BoolSliceSetting

NewBoolSliceSetting creates a BoolSliceSetting with the given default value.

func (*BoolSliceSetting) SetValue

func (s *BoolSliceSetting) SetValue(v interface{}) error

SetValue changes the underlying []bool.

func (*BoolSliceSetting) Value

func (s *BoolSliceSetting) Value() interface{}

Value returns the underlying []bool.

type DurationSetting

type DurationSetting struct {
	*BaseSetting
	DurationValue *time.Duration
}

DurationSetting manages an instance of time.Duration

func NewDurationSetting

func NewDurationSetting(name string, description string, fallback time.Duration) *DurationSetting

NewDurationSetting creates a DurationSetting with the given default value.

func (*DurationSetting) SetValue

func (s *DurationSetting) SetValue(v interface{}) error

SetValue changes the underlying time.Duration.

func (*DurationSetting) Value

func (s *DurationSetting) Value() interface{}

Value returns the underlying time.Duration.

type DurationSliceSetting

type DurationSliceSetting struct {
	*BaseSetting
	DurationSliceValue *[]time.Duration
}

DurationSliceSetting manages an instance of []time.Duration

func NewDurationSliceSetting

func NewDurationSliceSetting(name string, description string, fallback []time.Duration) *DurationSliceSetting

NewDurationSliceSetting creates a DurationSliceSetting with the given default value.

func (*DurationSliceSetting) SetValue

func (s *DurationSliceSetting) SetValue(v interface{}) error

SetValue changes the underlying []time.Duration.

func (*DurationSliceSetting) Value

func (s *DurationSliceSetting) Value() interface{}

Value returns the underlying []time.Duration.

type Float32Setting

type Float32Setting struct {
	*BaseSetting
	Float32Value *float32
}

Float32Setting manages an instance of float32

func NewFloat32Setting

func NewFloat32Setting(name string, description string, fallback float32) *Float32Setting

NewFloat32Setting creates a Float32Setting with the given default value.

func (*Float32Setting) SetValue

func (s *Float32Setting) SetValue(v interface{}) error

SetValue changes the underlying float32.

func (*Float32Setting) Value

func (s *Float32Setting) Value() interface{}

Value returns the underlying float32.

type Float64Setting

type Float64Setting struct {
	*BaseSetting
	Float64Value *float64
}

Float64Setting manages an instance of float64

func NewFloat64Setting

func NewFloat64Setting(name string, description string, fallback float64) *Float64Setting

NewFloat64Setting creates a Float64Setting with the given default value.

func (*Float64Setting) SetValue

func (s *Float64Setting) SetValue(v interface{}) error

SetValue changes the underlying float64.

func (*Float64Setting) Value

func (s *Float64Setting) Value() interface{}

Value returns the underlying float64.

type Group

type Group interface {
	Name() string
	Description() string
	Groups() []Group
	Settings() []Setting
}

Group is a container for a collection of settings. The container can contain any number of nested sub-trees.

func Convert

func Convert(v interface{}) (Group, error)

Convert a struct into a Group. This function recurses over all nested structs which are gathered as sub-trees.

func GroupFromComponent

func GroupFromComponent(v interface{}) (Group, error)

GroupFromComponent works like Convert to change a struct into a Group but is able to do so with an implementation of the Component contract.

type Int16Setting

type Int16Setting struct {
	*BaseSetting
	Int16Value *int16
}

Int16Setting manages an instance of int16

func NewInt16Setting

func NewInt16Setting(name string, description string, fallback int16) *Int16Setting

NewInt16Setting creates a Int16Setting with the given default value.

func (*Int16Setting) SetValue

func (s *Int16Setting) SetValue(v interface{}) error

SetValue changes the underlying int16.

func (*Int16Setting) Value

func (s *Int16Setting) Value() interface{}

Value returns the underlying int16.

type Int32Setting

type Int32Setting struct {
	*BaseSetting
	Int32Value *int32
}

Int32Setting manages an instance of int32

func NewInt32Setting

func NewInt32Setting(name string, description string, fallback int32) *Int32Setting

NewInt32Setting creates a Int32Setting with the given default value.

func (*Int32Setting) SetValue

func (s *Int32Setting) SetValue(v interface{}) error

SetValue changes the underlying int32.

func (*Int32Setting) Value

func (s *Int32Setting) Value() interface{}

Value returns the underlying int32.

type Int64Setting

type Int64Setting struct {
	*BaseSetting
	Int64Value *int64
}

Int64Setting manages an instance of int64

func NewInt64Setting

func NewInt64Setting(name string, description string, fallback int64) *Int64Setting

NewInt64Setting creates a Int64Setting with the given default value.

func (*Int64Setting) SetValue

func (s *Int64Setting) SetValue(v interface{}) error

SetValue changes the underlying int64.

func (*Int64Setting) Value

func (s *Int64Setting) Value() interface{}

Value returns the underlying int64.

type Int8Setting

type Int8Setting struct {
	*BaseSetting
	Int8Value *int8
}

Int8Setting manages an instance of int8

func NewInt8Setting

func NewInt8Setting(name string, description string, fallback int8) *Int8Setting

NewInt8Setting creates a Int8Setting with the given default value.

func (*Int8Setting) SetValue

func (s *Int8Setting) SetValue(v interface{}) error

SetValue changes the underlying int8.

func (*Int8Setting) Value

func (s *Int8Setting) Value() interface{}

Value returns the underlying int8.

type IntSetting

type IntSetting struct {
	*BaseSetting
	IntValue *int
}

IntSetting manages an instance of int

func NewIntSetting

func NewIntSetting(name string, description string, fallback int) *IntSetting

NewIntSetting creates a IntSetting with the given default value.

func (*IntSetting) SetValue

func (s *IntSetting) SetValue(v interface{}) error

SetValue changes the underlying int.

func (*IntSetting) Value

func (s *IntSetting) Value() interface{}

Value returns the underlying int.

type IntSliceSetting

type IntSliceSetting struct {
	*BaseSetting
	IntSliceValue *[]int
}

IntSliceSetting manages an instance of []int

func NewIntSliceSetting

func NewIntSliceSetting(name string, description string, fallback []int) *IntSliceSetting

NewIntSliceSetting creates a IntSliceSetting with the given default value.

func (*IntSliceSetting) SetValue

func (s *IntSliceSetting) SetValue(v interface{}) error

SetValue changes the underlying []int.

func (*IntSliceSetting) Value

func (s *IntSliceSetting) Value() interface{}

Value returns the underlying []int.

type MapSource

type MapSource struct {
	Map map[string]interface{}
}

MapSource implements the Source interface for any map[string]interface{}. This implementation is intended to support the most common configuration sources which would be JSON, YAML, and ENV.

Note: All keys should lower case (if applicable for the character set)

as lower case will also be applied to all lookup paths.

func NewEnvSource

func NewEnvSource(env []string) (*MapSource, error)

NewEnvSource uses the given environment to generate a configuration source. The "_" character is used as a delimeter and each one will result in a subtree.

func NewFileSource

func NewFileSource(path string) (*MapSource, error)

NewFileSource reads in the given file and parsing it with multiple encodings to find one that works.

func NewJSONSource

func NewJSONSource(b []byte) (*MapSource, error)

NewJSONSource generates a config source from a JSON string.

func NewMapSource

func NewMapSource(m map[string]interface{}) *MapSource

NewMapSource is the recommended way to create a MapSource instance. While they can be created with any map[string]interface{}, this constructor ensures that all keys of the map have a consistent case applied.

func NewYAMLSource

func NewYAMLSource(b []byte) (*MapSource, error)

NewYAMLSource generates a config source from a YAML string.

func (*MapSource) Get

func (s *MapSource) Get(_ context.Context, path ...string) (interface{}, bool)

Get traverses a configuration map until it finds the requested element or reaches a dead end. Variable expansion is supported when the value is a string with ${} wrapped around a key.

type MultiSource

type MultiSource []Source

MultiSource is an ordered set of Sources from which to pull values. It will search until the first Source returns a found value or will return false for found.

func (MultiSource) Get

func (ms MultiSource) Get(ctx context.Context, path ...string) (interface{}, bool)

Get a value from the ordered set of Sources. Variable expansion is supported when the value is a string with ${} wrapped around a key.

type PrefixSource

type PrefixSource struct {
	Source Source
	Prefix []string
}

PrefixSource is a wrapper for other Source implementations that adds a path element to the front of every lookup.

func (*PrefixSource) Get

func (s *PrefixSource) Get(ctx context.Context, path ...string) (interface{}, bool)

Get a value with a prefixed path.

type Setting

type Setting interface {
	Name() string
	Description() string
	Value() interface{}
	SetValue(v interface{}) error
}

Setting is a generic container for all configuration values. Each implementation should maintain its own internal typing.

type SettingGroup

type SettingGroup struct {
	NameValue        string
	DescriptionValue string
	GroupValues      []Group
	SettingValues    []Setting
}

SettingGroup an implementation of Group. This component is predominantly used by the struct converter to map native types into Setting and Group types.

func (*SettingGroup) Description

func (g *SettingGroup) Description() string

Description returns the group description.

func (*SettingGroup) Groups

func (g *SettingGroup) Groups() []Group

Groups returns any sub-trees in the current group.

func (*SettingGroup) Name

func (g *SettingGroup) Name() string

Name returns the group name as it appears in the configuration.

func (*SettingGroup) Settings

func (g *SettingGroup) Settings() []Setting

Settings returns any settings attached directly to this group.

type Source

type Source interface {
	Get(ctx context.Context, path ...string) (interface{}, bool)
}

Source is the main entry point for fetching configuration values. The boolean value must be false if the source is unable to find an entry for the given path. If found, the raw value is returned and it is the responsibility of the consumer to verify the type or quality of the value.

type StringMapStringSetting added in v0.4.0

type StringMapStringSetting struct {
	*BaseSetting
	StringMapStringValue *map[string]string
}

StringMapStringSetting manages an instance of map[string]string.

func NewStringMapStringSetting added in v0.4.0

func NewStringMapStringSetting(name string, description string, fallback map[string]string) *StringMapStringSetting

NewStringMapStringSetting creates a StringMapStringSetting with the given default value.

func (*StringMapStringSetting) SetValue added in v0.4.0

func (m *StringMapStringSetting) SetValue(v interface{}) error

SetValue changes the underlying map[string][]string.

func (*StringMapStringSetting) Value added in v0.4.0

func (m *StringMapStringSetting) Value() interface{}

Value returns the underlying map[string][]string.

type StringMapStringSliceSetting added in v0.3.0

type StringMapStringSliceSetting struct {
	*BaseSetting
	StringMapStringSliceValue *map[string][]string
}

StringMapStringSliceSetting manages an instance of map[string][]string.

func NewStringMapStringSliceSetting added in v0.3.0

func NewStringMapStringSliceSetting(name string, description string, fallback map[string][]string) *StringMapStringSliceSetting

NewStringMapStringSliceSetting creates a StringMapStringSliceSetting with the given default value.

func (*StringMapStringSliceSetting) SetValue added in v0.3.0

func (m *StringMapStringSliceSetting) SetValue(v interface{}) error

SetValue changes the underlying map[string][]string.

func (*StringMapStringSliceSetting) Value added in v0.3.0

func (m *StringMapStringSliceSetting) Value() interface{}

Value returns the underlying map[string][]string.

type StringSetting

type StringSetting struct {
	*BaseSetting
	StringValue *string
}

StringSetting manages an instance of string

func NewStringSetting

func NewStringSetting(name string, description string, fallback string) *StringSetting

NewStringSetting creates a StringSetting with the given default value.

func (*StringSetting) SetValue

func (s *StringSetting) SetValue(v interface{}) error

SetValue changes the underlying string.

func (*StringSetting) Value

func (s *StringSetting) Value() interface{}

Value returns the underlying string.

type StringSliceSetting

type StringSliceSetting struct {
	*BaseSetting
	StringSliceValue *[]string
}

StringSliceSetting manages an instance of []string

func NewStringSliceSetting

func NewStringSliceSetting(name string, description string, fallback []string) *StringSliceSetting

NewStringSliceSetting creates a StringSliceSetting with the given default value.

func (*StringSliceSetting) SetValue

func (s *StringSliceSetting) SetValue(v interface{}) error

SetValue changes the underlying []string.

func (*StringSliceSetting) Value

func (s *StringSliceSetting) Value() interface{}

Value returns the underlying []string.

type TimeSetting

type TimeSetting struct {
	*BaseSetting
	TimeValue *time.Time
}

TimeSetting manages an instance of time.Time

func NewTimeSetting

func NewTimeSetting(name string, description string, fallback time.Time) *TimeSetting

NewTimeSetting creates a TimeSetting with the given default value.

func (*TimeSetting) SetValue

func (s *TimeSetting) SetValue(v interface{}) error

SetValue changes the underlying time.Time.

func (*TimeSetting) Value

func (s *TimeSetting) Value() interface{}

Value returns the underlying time.Time.

type Uint16Setting

type Uint16Setting struct {
	*BaseSetting
	Uint16Value *uint16
}

Uint16Setting manages an instance of uint16

func NewUint16Setting

func NewUint16Setting(name string, description string, fallback uint16) *Uint16Setting

NewUint16Setting creates a Uint16Setting with the given default value.

func (*Uint16Setting) SetValue

func (s *Uint16Setting) SetValue(v interface{}) error

SetValue changes the underlying uint16.

func (*Uint16Setting) Value

func (s *Uint16Setting) Value() interface{}

Value returns the underlying uint16.

type Uint32Setting

type Uint32Setting struct {
	*BaseSetting
	Uint32Value *uint32
}

Uint32Setting manages an instance of uint32

func NewUint32Setting

func NewUint32Setting(name string, description string, fallback uint32) *Uint32Setting

NewUint32Setting creates a Uint32Setting with the given default value.

func (*Uint32Setting) SetValue

func (s *Uint32Setting) SetValue(v interface{}) error

SetValue changes the underlying uint32.

func (*Uint32Setting) Value

func (s *Uint32Setting) Value() interface{}

Value returns the underlying uint32.

type Uint64Setting

type Uint64Setting struct {
	*BaseSetting
	Uint64Value *uint64
}

Uint64Setting manages an instance of uint64

func NewUint64Setting

func NewUint64Setting(name string, description string, fallback uint64) *Uint64Setting

NewUint64Setting creates a Uint64Setting with the given default value.

func (*Uint64Setting) SetValue

func (s *Uint64Setting) SetValue(v interface{}) error

SetValue changes the underlying uint64.

func (*Uint64Setting) Value

func (s *Uint64Setting) Value() interface{}

Value returns the underlying uint64.

type Uint8Setting

type Uint8Setting struct {
	*BaseSetting
	Uint8Value *uint8
}

Uint8Setting manages an instance of uint8

func NewUint8Setting

func NewUint8Setting(name string, description string, fallback uint8) *Uint8Setting

NewUint8Setting creates a Uint8Setting with the given default value.

func (*Uint8Setting) SetValue

func (s *Uint8Setting) SetValue(v interface{}) error

SetValue changes the underlying uint8.

func (*Uint8Setting) Value

func (s *Uint8Setting) Value() interface{}

Value returns the underlying uint8.

type UintSetting

type UintSetting struct {
	*BaseSetting
	UintValue *uint
}

UintSetting manages an instance of uint

func NewUintSetting

func NewUintSetting(name string, description string, fallback uint) *UintSetting

NewUintSetting creates a UintSetting with the given default value.

func (*UintSetting) SetValue

func (s *UintSetting) SetValue(v interface{}) error

SetValue changes the underlying uint.

func (*UintSetting) Value

func (s *UintSetting) Value() interface{}

Value returns the underlying uint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL