param

package
v0.0.0-...-8223eb1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

The param package is a management system for configuration parameters. Much like the standard library "flags" package, the param package allows parameters to be defined in the file they are needed without requiring direct linkage between the usage location and the configuration parser.

In typical use, each parameter is defined as a package-level variable. During initialization, the program provides a map[string]string containing parameter configuration data. This map is expected to be parsed from a configuration file.

Because the tasks are so similar, this package is implemented by re-using the low-level types from the standard "flag" module.

Example parameter declaration:

var threshold = param.Int("threshold", 5)

Parameter use:

if numUsed >= *threshold { ... }

Parsing from a config file:

var config struct {
    FormalValue  string
    Params       param.Values
}
yaml.Unmarshal(readConfigFile(), &config)
err := param.Parse(config.Params)

Index

Constants

This section is empty.

Variables

View Source
var DefaultParams flag.FlagSet

DefaultParams holds the default set of parameters, used by all package-level functions.

Functions

func Bool

func Bool(name string, value bool) *bool

Bool declares a new "bool"-typed parameter with the given default value.

func Float64

func Float64(name string, value float64) *float64

Float64 declares a new "float64"-typed parameter with the given default value.

func Int

func Int(name string, value int) *int

Int declares a new "int"-typed parameter with the given default value.

func Int64

func Int64(name string, value int64) *int64

Int64 declares a new "int64"-typed parameter with the given default value.

func Parse

func Parse(values Values) error

Parse parses the parameter assignments for the default set of parameters. See ParseFlags().

func ParseFlags

func ParseFlags(f *flag.FlagSet, values Values) error

ParseFlags parses a map of parameter assignments that are defined by a FlagSet.

func String

func String(name string, value string) *string

String declares a new "string"-typed parameter with the given default value.

Types

type Values

type Values map[string]string

Values is a type alias that can be used to help document the configuration values that are meant to be define parameters.

Jump to

Keyboard shortcuts

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