vipercfg

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

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

Loader implements config loader facilities using Viper.

func Init

func Init(opts ...Option) (*Loader, error)

Init initialises the config loader with given options and returns.

func (*Loader) Bool

func (l *Loader) Bool(key string, defaultValue bool) bool

Bool returns the boolean value set for the given key. Returns defaultValue if keys is not explicitly set.

func (*Loader) Duration

func (l *Loader) Duration(key string, defaultValue time.Duration) time.Duration

Duration returns the duration value set for the given key. Returns defaultValue if keys is not explicitly set.

func (*Loader) Float64

func (l *Loader) Float64(key string, defaultValue float64) float64

Float64 returns the float64 value set for the given key. Returns defaultValue if keys is not explicitly set.

func (*Loader) Int

func (l *Loader) Int(key string, defaultValue int) int

Int returns the int value set for the given key. Returns defaultValue if keys is not explicitly set.

func (*Loader) String

func (l *Loader) String(key string, defaultValue string) string

String returns the string value set for the given key. Returns defaultValue if keys is not explicitly set.

func (*Loader) Strings

func (l *Loader) Strings(key string, defaultValue []string) []string

Strings returns the list of string values set for the given key. Returns defaultValue if keys is not explicitly set.

func (*Loader) Viper

func (l *Loader) Viper() *viper.Viper

type Option

type Option func(l *Loader)

Option values can be provided to Load() for customisation.

func WithCobra

func WithCobra(cmd *cobra.Command, flagName string) Option

WithCobra enables reading config file overrides from a flag. When the flag is specified, it acts as the only file-based source of configs. If not specified, config files are auto-discovered.

func WithEnvPrefix

func WithEnvPrefix(prefix string) Option

WithEnvPrefix sets a prefix to be used for all config variables from environment.

func WithFile

func WithFile(filePath string) Option

WithFile sets a config file to use explicitly. When the filePath is not empty, it acts the only file-based source of configs. If empty, config files are auto-discovered.

func WithName

func WithName(name string) Option

WithName sets the configuration file title to be used for automatic discovery of config files.

func WithPaths

func WithPaths(paths ...string) Option

WithPaths overrides the default directories that are searched for config files.

Jump to

Keyboard shortcuts

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