settings

package
v1.25.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadGlobalConfig

func LoadGlobalConfig(path string, target any) error

LoadGlobalConfig loads a single global configuration file into the target struct. It is intentionally kept separate from LoadProjectConfig to remain fast and lightweight, as it does not need to support the heavy lifting of RecursiveMerge that project configurations require for deep map and slice overrides.

func LoadProjectConfig

func LoadProjectConfig(mainPath string, overridePaths []string, target any) error

LoadProjectConfig loads a main project config and merges optional overrides into the target struct.

func LoadProjectConfigFromContents

func LoadProjectConfigFromContents(mainContent []byte, overrides []OverrideConfig, target any) error

LoadProjectConfigFromContents loads a main project config and merges optional overrides from pre-read bytes.

func RecursiveMerge

func RecursiveMerge(dst, src map[string]any, replaceSlices bool) error

RecursiveMerge merges src into dst. Maps are merged recursively. Slices are appended by default, but replaced if replaceSlices is true. Values are overridden.

Types

type ConfigProvider

type ConfigProvider interface {
	GetString(key string) string
	GetInt(key string) int
	GetBool(key string) bool
	SetDefault(key string, value any)
	Set(key string, value any)
	Unmarshal(rawVal any) error
	Unset(key string)
	ReadConfig(path string) error
	ReadConfigFromBytes(data []byte) error
	MergeConfig(path string) error
}

ConfigProvider defines the interface for configuration providers.

func NewConfigProvider

func NewConfigProvider() ConfigProvider

NewConfigProvider returns a new ConfigProvider from the default factory.

type OverrideConfig

type OverrideConfig struct {
	Path    string
	Content []byte
}

OverrideConfig represents a configuration override with its source path and contents.

type ProviderFactory

type ProviderFactory interface {
	CreateConfigProvider() ConfigProvider
	LoadProjectConfig(mainPath string, overridePaths []string, target any) error
	LoadProjectConfigFromContents(mainContent []byte, overrides []OverrideConfig, target any) error
}

ProviderFactory defines the interface for creating ConfigProviders.

type ViperFactory

type ViperFactory struct{}

ViperFactory implements ProviderFactory using Viper.

func (*ViperFactory) CreateConfigProvider

func (vf *ViperFactory) CreateConfigProvider() ConfigProvider

CreateConfigProvider returns a new isolated ConfigProvider.

func (*ViperFactory) LoadProjectConfig

func (vf *ViperFactory) LoadProjectConfig(mainPath string, overridePaths []string, target any) error

LoadProjectConfig loads a main project config and merges optional overrides into the target struct.

func (*ViperFactory) LoadProjectConfigFromContents

func (vf *ViperFactory) LoadProjectConfigFromContents(mainContent []byte, overrides []OverrideConfig, target any) error

LoadProjectConfigFromContents loads a main project config and merges optional overrides from pre-read bytes.

Jump to

Keyboard shortcuts

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