config

package
v0.0.0-...-9649366 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

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

func LoadFile(dst interface{}, file string, opts Options) error

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

func LoadFiles(dst interface{}, files []string, opts Options) error

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

func WarnOnDeprecation(cfg interface{}, logger *zap.Logger)

WarnOnDeprecation emits a warning for every deprecated field

Types

type FlagStringSlice

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

func (i *FlagStringSlice) Set(value string) error

Set appends a string value to the slice.

func (*FlagStringSlice) String

func (i *FlagStringSlice) String() string

String() returns a string implmentation of the slice.

type Options

type Options struct {
	DisableUnmarshalStrict bool
	DisableValidate        bool

	// Expand provides values for templated strings of the form ${KEY}.
	// By default, we extract these values from the environment.
	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

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.

Jump to

Keyboard shortcuts

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