Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConfigNil = errors.New("configuration cannot be nil") ErrConfigRead = errors.New("failed to read configuration file") ErrConfigSave = errors.New("failed to save configuration file") ErrConfigWrite = errors.New("failed to write configuration file") ErrConfigNotFound = errors.New("configuration file not found at the specified path") ErrConfigMarshal = errors.New("failed to marshal configuration") ErrConfigUnmarshal = errors.New("failed to unmarshal configuration") ErrConfigValidation = errors.New("configuration validation failed") ErrConfigAlreadyLoaded = errors.New("configuration already loaded at this path") ErrConfigAlreadyLoadedInvalidType = errors.New("configuration already loading at this path has an invalid type") )
Predefined base errors (for wrapping)
var ErrConfigFailedToBindFlags = errors.New("failed to bind flags")
Use MoleyError for binding errors
Functions ¶
Types ¶
type BaseConfigManager ¶
type BaseConfigManager[T any] struct { // contains filtered or unexported fields }
WithOption is a function type that modifies the viper.Viper instance
func NewConfigManager ¶
func NewConfigManager[T any](path string, initial *T, options ...WithOption) *BaseConfigManager[T]
NewConfigManager creates a new BaseConfigManager instance
func (*BaseConfigManager[T]) Init ¶
func (m *BaseConfigManager[T]) Init() error
Init initializes the configuration manager by checking if the config file exists
func (*BaseConfigManager[T]) IsFound ¶
func (m *BaseConfigManager[T]) IsFound() bool
IsFound checks if the configuration file exists at the specified path
func (*BaseConfigManager[T]) Load ¶
func (m *BaseConfigManager[T]) Load(validate bool) (*T, error)
Load reads the configuration from the file and unmarshals it into the specified type
func (*BaseConfigManager[T]) Save ¶
func (m *BaseConfigManager[T]) Save(config *T, validate bool) error
Save writes the configuration to the file after validating it if required
type MoleyError ¶
type MoleyError struct {
Op string // operation or context
Err error // wrapped error
Msg string // additional message
}
MoleyError is a custom error type for wrapping errors in Moley
func (*MoleyError) Error ¶
func (e *MoleyError) Error() string
NewMoleyError creates a new MoleyError instance
func (*MoleyError) Unwrap ¶
func (e *MoleyError) Unwrap() error
Is checks if the error matches a specific type or message
type WithOption ¶
func WithBindEnv ¶
func WithBindEnv(prefix string) WithOption
func WithBindFlags ¶
func WithBindFlags(cmd *cobra.Command) WithOption