Documentation
¶
Index ¶
- Variables
- func CleanupSignalHandler()
- func ConvertValue(value interface{}, targetType reflect.Type) (interface{}, error)
- func DefaultValue[T any](x T) func() T
- func IgnoreFlags(flags ...string)
- func Validate(configName string, config map[string]interface{}) error
- type ConfigHandler
- type DefaultLogger
- func (dl *DefaultLogger) Debug(msg string, args ...interface{})
- func (dl *DefaultLogger) Debugf(format string, args ...interface{})
- func (dl *DefaultLogger) Error(msg string, args ...interface{})
- func (dl *DefaultLogger) Errorf(format string, args ...interface{})
- func (dl *DefaultLogger) Fatal(msg string, args ...interface{})
- func (dl *DefaultLogger) Fatalf(format string, args ...interface{})
- func (dl *DefaultLogger) Info(msg string, args ...interface{})
- func (dl *DefaultLogger) Infof(format string, args ...interface{})
- func (dl *DefaultLogger) Warn(msg string, args ...interface{})
- func (dl *DefaultLogger) Warnf(format string, args ...interface{})
- type NoopLogger
- func (nl *NoopLogger) Debug(msg string, args ...interface{})
- func (nl *NoopLogger) Error(msg string, args ...interface{})
- func (nl *NoopLogger) Fatal(msg string, args ...interface{})
- func (nl *NoopLogger) Info(msg string, args ...interface{})
- func (nl *NoopLogger) Warn(msg string, args ...interface{})
- type Option
- func WithAutoSave() Option
- func WithConfigHandler(handler ConfigHandler) Option
- func WithDefaultFileConfig(filename string) Option
- func WithFileConfig(filename string) Option
- func WithFileConfigParamName(argName string) Option
- func WithFlagSet(fs *flag.FlagSet) Option
- func WithHTTPConfig(httpLoader *http.Request, httpSaver *http.Request) Option
- func WithName(name string) Option
- func WithSkipEnvironment() Option
- func WithValidation(key string, validator Validator) Option
- type Structure
- func (c *Structure) AddValidator(key string, validator Validator)
- func (c *Structure) CheckUnrecognizedItems(s interface{})
- func (c *Structure) Get(key string) (interface{}, bool)
- func (c *Structure) GetFlagSet() *flag.FlagSet
- func (c *Structure) GetHelpTag(key string) string
- func (c *Structure) GetJSONBytes() []byte
- func (c *Structure) Init(parent interface{}, options ...Option)
- func (c *Structure) InitMyParent(options ...Option)
- func (c *Structure) InitSelf(options ...Option)
- func (c *Structure) NewFlag(configVarName string, defaultValue interface{}, configDescription string)
- func (c *Structure) RegisterValidator(key string, validator Validator)
- func (c *Structure) Reload() error
- func (c *Structure) ReloadConfig() error
- func (c *Structure) Set(key string, value interface{}) error
- func (c *Structure) String() string
- func (c *Structure) Validate() error
- func (c *Structure) ValidateKey(key string) error
- type ValidationError
- type ValidationErrors
- type Validator
- func All(validators ...Validator) Validator
- func Any(validators ...Validator) Validator
- func Custom(fn func(interface{}) error) Validator
- func Email() Validator
- func MaxLength(max int) Validator
- func MinLength(min int) Validator
- func OneOf(options ...interface{}) Validator
- func Range(min, max float64) Validator
- func Regex(pattern string) Validator
- func Required() Validator
- func URL() Validator
Constants ¶
This section is empty.
Variables ¶
var ( ErrorWrapper errorWrapper = defaultErrorWrapper Logger logger = NewDefaultLogger() )
Functions ¶
func CleanupSignalHandler ¶ added in v1.0.22
func CleanupSignalHandler()
CleanupSignalHandler allows for graceful cleanup of the signal handler This should be called in tests or when the application wants to clean up
func ConvertValue ¶ added in v1.0.15
ConvertValue converts a value to the target type This function extracts common type conversion logic from set() and dynamicVar.Set()
func DefaultValue ¶
func DefaultValue[T any](x T) func() T
DefaultValue returns a function that returns the type of the input parameter X
func IgnoreFlags ¶
func IgnoreFlags(flags ...string)
Types ¶
type ConfigHandler ¶ added in v1.0.22
type ConfigHandler interface {
// IsDefault should return true if the application may continue to start up if an error
// is returned from [ConfigHandler.LoadConfig].
IsDefault() bool
// LoadConfig should load the JSON representation of the config.
LoadConfig() (json.RawMessage, error)
// SaveConfig should save the JSON representation of the config.
SaveConfig(json.RawMessage) error
}
type DefaultLogger ¶ added in v1.0.19
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger is the default implementation of ExtendedLogger
func NewDefaultLogger ¶ added in v1.0.19
func NewDefaultLogger() *DefaultLogger
NewDefaultLogger creates a new DefaultLogger with the specified level
func (*DefaultLogger) Debug ¶ added in v1.0.19
func (dl *DefaultLogger) Debug(msg string, args ...interface{})
Debug logs a debug message
func (*DefaultLogger) Debugf ¶ added in v1.0.19
func (dl *DefaultLogger) Debugf(format string, args ...interface{})
func (*DefaultLogger) Error ¶ added in v1.0.19
func (dl *DefaultLogger) Error(msg string, args ...interface{})
Error logs an error message
func (*DefaultLogger) Errorf ¶ added in v1.0.19
func (dl *DefaultLogger) Errorf(format string, args ...interface{})
func (*DefaultLogger) Fatal ¶ added in v1.0.19
func (dl *DefaultLogger) Fatal(msg string, args ...interface{})
Fatal logs a fatal message and exits
func (*DefaultLogger) Fatalf ¶ added in v1.0.19
func (dl *DefaultLogger) Fatalf(format string, args ...interface{})
func (*DefaultLogger) Info ¶ added in v1.0.19
func (dl *DefaultLogger) Info(msg string, args ...interface{})
Info logs an info message
func (*DefaultLogger) Infof ¶ added in v1.0.19
func (dl *DefaultLogger) Infof(format string, args ...interface{})
func (*DefaultLogger) Warn ¶ added in v1.0.19
func (dl *DefaultLogger) Warn(msg string, args ...interface{})
Warn logs a warning message
func (*DefaultLogger) Warnf ¶ added in v1.0.19
func (dl *DefaultLogger) Warnf(format string, args ...interface{})
type NoopLogger ¶ added in v1.0.19
type NoopLogger struct{}
NoopLogger is a logger that does nothing
func (*NoopLogger) Debug ¶ added in v1.0.19
func (nl *NoopLogger) Debug(msg string, args ...interface{})
Debug does nothing
func (*NoopLogger) Error ¶ added in v1.0.19
func (nl *NoopLogger) Error(msg string, args ...interface{})
Error does nothing
func (*NoopLogger) Fatal ¶ added in v1.0.19
func (nl *NoopLogger) Fatal(msg string, args ...interface{})
Fatal does nothing
func (*NoopLogger) Info ¶ added in v1.0.19
func (nl *NoopLogger) Info(msg string, args ...interface{})
Info does nothing
func (*NoopLogger) Warn ¶ added in v1.0.19
func (nl *NoopLogger) Warn(msg string, args ...interface{})
Warn does nothing
type Option ¶ added in v1.0.3
Option is a function that configures a Structure
func WithAutoSave ¶ added in v1.0.14
func WithAutoSave() Option
WithAutoSave enables automatic saving of configuration on program exit
func WithConfigHandler ¶ added in v1.0.22
func WithConfigHandler(handler ConfigHandler) Option
WithConfigHandler uses the given ConfigHandler to save and load configuration.
func WithDefaultFileConfig ¶ added in v1.0.9
withFileConfig sets the config source/dest to a filename, and ignores if unable to find file
func WithFileConfig ¶ added in v1.0.3
withFileConfig sets the config source/dest to a filename, and logs and error if unable to find file
func WithFileConfigParamName ¶ added in v1.0.7
WithFileConfigParamName sets the config source/dest to a filename defined in the command line arguments
func WithFlagSet ¶ added in v1.0.15
WithFlagSet sets a custom FlagSet for the configuration
func WithHTTPConfig ¶ added in v1.0.3
WithHTTPConfig sets the config source/dest to a filename
func WithSkipEnvironment ¶ added in v1.0.3
func WithSkipEnvironment() Option
WithSkipEnvironment skips loading from environment variables
func WithValidation ¶ added in v1.0.15
WithValidation adds a validator for a configuration key
type Structure ¶ added in v1.0.2
type Structure struct {
// Field to store a dedicated FlagSet instead of using flag.CommandLine
FlagSet *flag.FlagSet
// contains filtered or unexported fields
}
func (*Structure) AddValidator ¶ added in v1.0.19
AddValidator adds a validator for a configuration key
func (*Structure) CheckUnrecognizedItems ¶ added in v1.0.2
func (c *Structure) CheckUnrecognizedItems(s interface{})
func (*Structure) Get ¶ added in v1.0.2
Get gets a configuration value and whether it exists from the configData
func (*Structure) GetFlagSet ¶ added in v1.0.15
GetFlagSet returns the FlagSet used by this configuration This allows applications to register the FlagSet with their own flag parsing system
func (*Structure) GetHelpTag ¶ added in v1.0.5
func (*Structure) GetJSONBytes ¶ added in v1.0.3
func (*Structure) InitMyParent ¶ added in v1.0.16
InitMyParent automatically determines the parent struct that contains this Structure and calls Init() with that parent.
func (*Structure) NewFlag ¶ added in v1.0.3
func (c *Structure) NewFlag(configVarName string, defaultValue interface{}, configDescription string)
NewFlag creates a new configuration item, using the type of the defaultValue
func (*Structure) RegisterValidator ¶ added in v1.0.15
RegisterValidator registers a validation function for a configuration key
func (*Structure) ReloadConfig ¶ added in v1.0.15
ReloadConfig reloads the configuration from sources
func (*Structure) Set ¶ added in v1.0.2
Set sets a configuration value and then updates the config struct as well
func (*Structure) Validate ¶ added in v1.0.15
Validate validates all configuration values against registered validators
func (*Structure) ValidateKey ¶ added in v1.0.15
ValidateKey validates a specific configuration key against its registered validator
type ValidationError ¶ added in v1.0.19
ValidationError represents an error that occurred during validation
func (ValidationError) Error ¶ added in v1.0.19
func (v ValidationError) Error() string
Error implements the error interface
func (ValidationError) Unwrap ¶ added in v1.0.19
func (v ValidationError) Unwrap() error
Unwrap returns the underlying error
type ValidationErrors ¶ added in v1.0.19
type ValidationErrors []ValidationError
ValidationErrors represents multiple validation errors
func (ValidationErrors) Error ¶ added in v1.0.19
func (v ValidationErrors) Error() string
Error implements the error interface
type Validator ¶ added in v1.0.15
type Validator func(interface{}) error
Validator is a function that validates a configuration value
func Email ¶ added in v1.0.19
func Email() Validator
Email returns a validator that checks if a string is a valid email address
func MaxLength ¶ added in v1.0.19
MaxLength returns a validator that checks if a string or slice has at most max elements
func MinLength ¶ added in v1.0.19
MinLength returns a validator that checks if a string or slice has at least min elements
func OneOf ¶ added in v1.0.19
func OneOf(options ...interface{}) Validator
OneOf returns a validator that checks if a value is one of the provided options
func Regex ¶ added in v1.0.19
Regex returns a validator that checks if a string matches a regular expression