viper

package
v0.0.0-...-269064b Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: BSD-3-Clause Imports: 9 Imported by: 2

Documentation

Overview

Package viper provides utilities to work with `github.com/spf13/viper`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindFlags

func BindFlags(cmd *cobra.Command, params []cli.Param, vp *lib.Viper) error

BindFlags will detect flags used to link parameters to the command and properly bind each one to the provided viper instance.

Types

type Config

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

Config provides a simple interface to manage application settings using Viper.

func ConfigHandler

func ConfigHandler(app string, opts *ConfigOptions) *Config

ConfigHandler returns a new configuration management instance configured for the provided `app` identifier. Optional locations can be provided to specify valid paths to look for a config file.

func (*Config) FileUsed

func (c *Config) FileUsed() string

FileUsed returns the full path of the configuration file used to load the settings.

func (*Config) Get

func (c *Config) Get(key string) interface{}

Get the value registered for `key`, if any.

func (*Config) Internals

func (c *Config) Internals() *lib.Viper

Internals expose the private viper instance used by the configuration manager; use with care.

func (*Config) IsSet

func (c *Config) IsSet(key string) bool

IsSet returns true if a value is available for `key`.

func (*Config) Read

func (c *Config) Read(src io.Reader) error

Read configuration values from the provided `src` element.

func (*Config) ReadFile

func (c *Config) ReadFile(ignoreNotFound bool) error

ReadFile will try to load configuration values from the local filesystem; optionally ignore the error produced when no configuration file was found.

func (*Config) Set

func (c *Config) Set(key string, value interface{})

Set the provided `key` to `value`.

func (*Config) Unmarshal

func (c *Config) Unmarshal(receiver interface{}, key string) error

Unmarshal will load configuration values into `receiver`; which must be a pointer. A `key` value can be provided to load a specific subsection of the settings available.

type ConfigOptions

type ConfigOptions struct {
	// Configuration file name (without extension). Defaults to `config`.
	FileName string

	// Configuration file extension. This will be used internally to automatically
	// decode its contents accordingly. Defaults to `yaml`
	FileType string

	// Additional locations to look for the configuration file.
	Locations []string
}

ConfigOptions adjust the internal behavior of the configuration handler.

Jump to

Keyboard shortcuts

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