confutil

package
v0.6.14 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapContext

func WrapContext(ctx context.Context, c Config) context.Context

Types

type Config added in v0.6.14

type Config interface {
	Get(format string, args ...any) any
	GetBool(format string, args ...any) bool
	GetDuration(format string, args ...any) time.Duration
	GetFloat64(format string, args ...any) float64
	GetInt(format string, args ...any) int
	GetInt32(format string, args ...any) int32
	GetInt64(format string, args ...any) int64
	GetIntSlice(format string, args ...any) []int
	GetSizeInBytes(format string, args ...any) uint
	GetString(format string, args ...any) string
	GetStringMap(format string, args ...any) map[string]any
	GetStringMapString(format string, args ...any) map[string]string
	GetStringMapStringSlice(format string, args ...any) map[string][]string
	GetStringSlice(format string, args ...any) []string
	GetTime(format string, args ...any) time.Time
	GetUint(format string, args ...any) uint
	GetUint8(format string, args ...any) uint8
	GetUint16(format string, args ...any) uint16
	GetUint32(format string, args ...any) uint32
	GetUint64(format string, args ...any) uint64
	IsSet(format string, args ...any) bool
}

Config is the read side of the app's configuration, handed to services through the Init context. Every getter takes a format string: with no args it is the key itself, otherwise it is fmt.Sprintf-ed first, so a service reads under its own root - GetInt("%s.connection.max_open", nameutil.ConfigRoot(m.name)) - rather than a hardcoded one. Getters mirror viper's: an absent key reads as the zero value, never an error.

func FromContext

func FromContext(ctx context.Context) Config

FromContext returns the Config the supervisor wrapped into the Init context. It never returns nil: with no config in the context it returns an empty Config, so every getter yields the zero value - a missing config looks like "all defaults", so a mandatory setting is validated in Init.

func New added in v0.6.14

func New(v *viper.Viper) Config

New wraps a viper instance. A nil viper wraps an empty one, so the result is always usable and every getter yields the zero value - the same never-nil doctrine FromContext follows.

Jump to

Keyboard shortcuts

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