config

package
v0.0.0-...-f9bc49b Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedConfigFileFormat is returned when the config file format
	// is not supported by the provider.
	ErrUnsupportedConfigFileFormat = errors.New("unsupported config file format, only yaml, json and toml are supported")
)

Functions

This section is empty.

Types

type Provider

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

Provider is a simple config provider for the CLI that can fall back to a config file or environment variables. This is an alternative approach to using the viper library that was a pain to integrate with cobra in providing config file and env var defaults across multiple levels of subcommands.

The precendence of config values is as follows: 1. Flags 2. Environment variables 3. Config file 4. Flag defaults 5. Config provider defaults

Provider only supports strings, booleans, integers and floats as configuration values. Complex types such as arrays, structs and maps are not supported.

YAML, JSON and TOML are supported as config file formats.

func NewProvider

func NewProvider() *Provider

NewProvider creates a new Provider of configuration values for the CLI.

func (*Provider) BindEnvVar

func (p *Provider) BindEnvVar(configName string, envVarName string)

func (*Provider) BindPFlag

func (p *Provider) BindPFlag(configName string, flag *pflag.Flag)

func (*Provider) GetBool

func (p *Provider) GetBool(configName string) (bool, bool)

func (*Provider) GetFloat32

func (p *Provider) GetFloat32(configName string) (float32, bool)

func (*Provider) GetFloat64

func (p *Provider) GetFloat64(configName string) (float64, bool)

func (*Provider) GetInt32

func (p *Provider) GetInt32(configName string) (int32, bool)

func (*Provider) GetInt64

func (p *Provider) GetInt64(configName string) (int64, bool)

func (*Provider) GetString

func (p *Provider) GetString(configName string) (string, bool)

GetString returns the value of a configuration value as a string. It also returns a boolean indicating whether the value was set by the user or if it's a default value. `true` means the value is a default value.

func (*Provider) GetUint32

func (p *Provider) GetUint32(configName string) (uint32, bool)

func (*Provider) GetUint64

func (p *Provider) GetUint64(configName string) (uint64, bool)

func (*Provider) LoadConfigFile

func (p *Provider) LoadConfigFile(configFilePath string) error

func (*Provider) SetDefault

func (p *Provider) SetDefault(configName, value string)

Jump to

Keyboard shortcuts

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