Thanks to visit codestin.com
Credit goes to pkg.go.dev

shared

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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)

View Source
var ErrConfigFailedToBindFlags = errors.New("failed to bind flags")

Use MoleyError for binding errors

Functions

func WrapError

func WrapError(err error, msg string) error

WrapError automatically captures the caller information and wraps an error This is the preferred way to wrap errors as it reduces boilerplate

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

type WithOption = func(*viper.Viper) error

func WithBindEnv

func WithBindEnv(prefix string) WithOption

func WithBindFlags

func WithBindFlags(cmd *cobra.Command) WithOption

Jump to

Keyboard shortcuts

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