config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToStruct

func ToStruct[T any](cfg *Config, key string) (t T, err error)

Types

type Config

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

Config is a higher-level Viper wrapper that comes with some extra features

func NewConfig

func NewConfig(v *viper.Viper, references map[string]*viper.Viper) *Config

NewConfig construct a config from viper instances

func NewConfigFromPaths

func NewConfigFromPaths(path string, referencePaths map[string]string) (*Config, error)

NewConfigFromPaths construct a config from paths

func (*Config) Exists

func (g *Config) Exists(key string) bool

Exists check a key exists or not

func (*Config) Get

func (g *Config) Get(key string) any

func (*Config) GetBool

func (g *Config) GetBool(k string) bool

func (*Config) GetDuration

func (g *Config) GetDuration(k string) time.Duration

func (*Config) GetFloat64

func (g *Config) GetFloat64(k string) float64

func (*Config) GetInt

func (g *Config) GetInt(k string) int

func (*Config) GetInt32

func (g *Config) GetInt32(k string) int32

func (*Config) GetInt64

func (g *Config) GetInt64(k string) int64

func (*Config) GetIntSlice

func (g *Config) GetIntSlice(k string) []int

func (*Config) GetString

func (g *Config) GetString(k string) string

func (*Config) GetStringMap

func (g *Config) GetStringMap(k string) map[string]any

func (*Config) GetStringSlice

func (g *Config) GetStringSlice(k string) []string

func (*Config) GetTime

func (g *Config) GetTime(k string) time.Time

func (*Config) Of

func (g *Config) Of(prefix string) *Config

Of returns a new config instance with provided key prefix Example:

cfg.GetString("foo.bar") == cfg.Of("foo").GetString("bar") // true

func (*Config) Set

func (g *Config) Set(key string, value any)

func (*Config) SetDefault

func (g *Config) SetDefault(key string, value any)

type Wrapper

type Wrapper wrapper.Wrapper[*Config]

Wrapper is config wrapper method, it can be used to manipulate config on injection process

Jump to

Keyboard shortcuts

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