config

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 33

Documentation

Overview

Package config provides utilities for loading configuration files.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump added in v0.15.0

func Dump(cfg interface{}, dst io.Writer) error

Dump writes the given configuration to stream dst as YAML.

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 added in v0.11.0

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

WarnOnDeprecation emits a warning for every deprecated field

Types

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 configflag provides a utility for registering config related command line options with the stdlib flag package.
Package configflag provides a utility for registering config related command line options with the stdlib flag package.
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.

Jump to

Keyboard shortcuts

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