Documentation
¶
Overview ¶
Package config provides utilities for loading configuration files.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadFile ¶
LoadFile loads a config from a file.
Example ¶
package main
import (
"fmt"
"log"
"github.com/m3db/m3/src/x/config"
)
type configuration struct {
ListenAddress string `yaml:"listenAddress" validate:"nonzero"`
}
func main() {
var cfg configuration
file := "testdata/conf.yaml"
if err := config.LoadFile(&cfg, file, config.Options{}); err != nil {
log.Fatal(err)
}
fmt.Printf("listenAddress: %s\n", cfg.ListenAddress)
}
Output: listenAddress: 0.0.0.0:8392
func LoadFiles ¶
LoadFiles loads a config from list of files. If value for a property is present in multiple files, the value from the last file will be applied. Validation is done after merging all values.
func WarnOnDeprecation ¶ added in v0.11.0
WarnOnDeprecation emits a warning for every deprecated field
Types ¶
type FlagStringSlice ¶ added in v0.13.0
type FlagStringSlice []string
FlagStringSlice represents a slice of strings. When used as a flag variable, it allows for multiple string values. For example, it can be used like this:
var configFiles FlagStringSlice flag.Var(&configFiles, "f", "configuration file(s)")
Then it can be invoked like this:
./app -f file1.yaml -f file2.yaml -f valueN.yaml
Finally, when the flags are parsed, the variable contains all the values.
Example ¶
The FlagStringSlice allows for multiple values when used as a flag variable.
package main
import (
"flag"
"fmt"
"github.com/m3db/m3/src/x/config"
)
func main() {
var configFiles config.FlagStringSlice
fs := flag.NewFlagSet("config", flag.PanicOnError)
fs.Var(&configFiles, "f", "config files")
fs.Parse([]string{"-f", "file1.yaml", "-f", "file2.yaml", "-f", "file3.yaml"})
fmt.Println("Config files:", configFiles)
}
Output: Config files: [file1.yaml file2.yaml file3.yaml]
func (*FlagStringSlice) Set ¶ added in v0.13.0
func (i *FlagStringSlice) Set(value string) error
Set appends a string value to the slice.
func (*FlagStringSlice) String ¶ added in v0.13.0
func (i *FlagStringSlice) String() string
String() returns a string implmentation of the slice.
type Options ¶
type Options struct {
DisableUnmarshalStrict bool
DisableValidate bool
Expand config.LookupFunc
}
Options is an options set used when parsing config.
type WorkerPoolPolicy ¶
type WorkerPoolPolicy struct {
// Determines if the worker pool automatically grows to capacity.
GrowOnDemand bool `yaml:"grow"`
// Size for static pools, initial size for dynamically growing pools.
Size int `yaml:"size"`
// The number of shards for the pool.
NumShards int64 `yaml:"shards"`
// The probablility that a worker is killed after completing the task.
KillWorkerProbability float64 `yaml:"killProbability" validate:"min=0.0,max=1.0"`
}
WorkerPoolPolicy specifies the policy for the worker pool.
func (WorkerPoolPolicy) Options ¶
func (w WorkerPoolPolicy) Options() (sync.PooledWorkerPoolOptions, int)
Options converts the worker pool policy to options, providing the options, as well as the default size for the worker pool.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package hostid provides a configuration struct for resolving a host ID from YAML.
|
Package hostid provides a configuration struct for resolving a host ID from YAML. |
|
Package listenaddress provides a configuration struct for resolving a listen address from YAML.
|
Package listenaddress provides a configuration struct for resolving a listen address from YAML. |