config

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config provides configuration management things.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSearchPaths

func DefaultSearchPaths() []string

DefaultSearchPaths returns default search directory paths for using in New.

Default paths slice include:

  • $HOME;
  • directory where executable is located;
  • current working directory.

Types

type Config

type Config interface {
	// Name returns config name
	Name() string

	// Backend returns backend configuration engine
	Backend() interface{}

	// Get can retrieve any value given the key to use.
	Get(key string) interface{}

	// GetString returns the value associated with the key as a string.
	GetString(key string) string

	// GetBool returns the value associated with the key as a bool.
	GetBool(key string) bool

	// GetInt returns the value associated with the key as an integer.
	GetInt(key string) int

	// GetFloat returns the value associated with the key as a float64.
	GetFloat(key string) float64

	// GetTime returns the value associated with the key as time.
	GetTime(key string) time.Time

	// GetDuration returns the value associated with the key as a duration.
	GetDuration(key string) time.Duration

	// GetIntSlice returns the value associated with the key as a slice of int values.
	GetIntSlice(key string) []int

	// GetStringSlice returns the value associated with the key as a slice of strings.
	GetStringSlice(key string) []string

	// GetStringMap returns the value associated with the key as a map of interfaces.
	GetStringMap(key string) map[string]interface{}

	// GetStringMapString returns the value associated with the key as a map of strings.
	GetStringMapString(key string) map[string]string

	// GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
	GetStringMapStringSlice(key string) map[string][]string

	// IsSet checks to see if the key has been set in any of the data locations.
	IsSet(key string) bool

	// InConfig checks to see if the given key (or an alias) is in the config file.
	InConfig(key string) bool

	// SetDefault sets the default value for this key.
	SetDefault(key string, value interface{})

	// Set sets the value for the key in the override register.
	Set(key string, value interface{})

	// All returns all values.
	All() map[string]interface{}

	// AllKeys returns all keys.
	AllKeys() []string
}

Config is the configuration interface.

func New

func New(name, typ string, searchPath ...string) (Config, error)

New creates a new configuration instance using default parameters.

Returned configuration uses files and environment variables for getting config data.

func NewTesting

func NewTesting(name string) Config

NewTesting creates a new configuration instance using default parameters suitable for using in tests.

This configuration supports only direct and ENV settings.

type Viper

type Viper struct {
	// contains filtered or unexported fields
}

Viper is the Viper configuration backend.

func (*Viper) All

func (v *Viper) All() map[string]interface{}

All returns all values.

func (*Viper) AllKeys

func (v *Viper) AllKeys() []string

AllKeys returns all keys.

func (*Viper) Backend

func (v *Viper) Backend() interface{}

Backend returns backend configuration engine.

func (*Viper) Get

func (v *Viper) Get(key string) interface{}

Get can retrieve any value given the key to use.

func (*Viper) GetBool

func (v *Viper) GetBool(key string) bool

GetBool returns the value associated with the key as a boolean.

func (*Viper) GetDuration

func (v *Viper) GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a duration.

func (*Viper) GetFloat

func (v *Viper) GetFloat(key string) float64

GetFloat returns the value associated with the key as a float64.

func (*Viper) GetInt

func (v *Viper) GetInt(key string) int

GetInt returns the value associated with the key as an integer.

func (*Viper) GetIntSlice

func (v *Viper) GetIntSlice(key string) []int

GetIntSlice returns the value associated with the key as a slice of int values.

func (*Viper) GetString

func (v *Viper) GetString(key string) string

GetString returns the value associated with the key as a string.

func (*Viper) GetStringMap

func (v *Viper) GetStringMap(key string) map[string]interface{}

GetStringMap returns the value associated with the key as a map of interfaces.

func (*Viper) GetStringMapString

func (v *Viper) GetStringMapString(key string) map[string]string

GetStringMapString returns the value associated with the key as a map of strings.

func (*Viper) GetStringMapStringSlice

func (v *Viper) GetStringMapStringSlice(key string) map[string][]string

GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.

func (*Viper) GetStringSlice

func (v *Viper) GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a slice of strings.

func (*Viper) GetTime

func (v *Viper) GetTime(key string) time.Time

GetTime returns the value associated with the key as time.

func (*Viper) InConfig

func (v *Viper) InConfig(key string) bool

InConfig checks to see if the given key (or an alias) is in the config file.

func (*Viper) IsSet

func (v *Viper) IsSet(key string) bool

IsSet checks to see if the key has been set in any of the data locations.

func (*Viper) Name

func (v *Viper) Name() string

func (*Viper) Set

func (v *Viper) Set(key string, value interface{})

Set sets the value for the key in the override register.

func (*Viper) SetDefault

func (v *Viper) SetDefault(key string, value interface{})

SetDefault sets the default value for this key.

Jump to

Keyboard shortcuts

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