Documentation
¶
Index ¶
- Constants
- func AsType[T any](c *Container) []T
- func Bind(target interface{}, data map[string]any, opts ...*Options) error
- func BindFromJSON(target interface{}, path string, opts ...*Options) error
- func BindFromYAML(target interface{}, path string, opts ...*Options) error
- func ConfigureChannel(name string, opts *LogOptions)
- func Get[T any](c *Container) (T, bool)
- func GetNamed[T any](c *Container, name string) (T, bool)
- func Has[T any](c *Container) bool
- func HasNamed[T any](c *Container, name string) bool
- func InitLogging(opts ...*LogOptions)
- func Inspect(source interface{}, opts ...*InspectOptions) (string, error)
- func Link(targets ...interface{}) error
- func Merge(target interface{}, data map[string]any, opts ...*Options) error
- func MergeFromJSON(target interface{}, path string, opts ...*Options) error
- func MergeFromYAML(target interface{}, path string, opts ...*Options) error
- func MustInspect(source interface{}, opts ...*InspectOptions) string
- func New[T any](data map[string]any, opts ...*Options) (*T, error)
- func NewDfHandler(opts *LogOptions) slog.Handler
- func NewFromJSON[T any](path string, opts ...*Options) (*T, error)
- func NewFromYAML[T any](path string, opts ...*Options) (*T, error)
- func NewPrettyHandler(level slog.Level, options *LogOptions) slog.Handler
- func NewPrettyHandlerWithChannel(level slog.Level, options *LogOptions, channelName string) slog.Handler
- func OfType[T any](c *Container) []T
- func ReconfigureChannel(name string, opts *LogOptions)
- func Remove[T any](c *Container) bool
- func RemoveChannel(name string)
- func RemoveNamed[T any](c *Container, name string) bool
- func Set(c *Container, object any)
- func SetAs[T any](c *Container, object T)
- func SetNamed(c *Container, name string, object any)
- func Unbind(source interface{}, opts ...*Options) (map[string]any, error)
- func UnbindToJSON(source interface{}, path string) error
- func UnbindToYAML(source interface{}, path string) error
- type Application
- type BindingError
- type Container
- type ConversionError
- type Converter
- type DfTag
- type Dynamic
- type Factory
- type FactoryFunc
- type FileError
- type Identifiable
- type IndexError
- type InspectData
- type InspectFormat
- type InspectObject
- type InspectOptions
- type InspectSummary
- type Linkable
- type Linker
- type LinkerOptions
- type LogBuilder
- func (b *LogBuilder) Debug(msg string)
- func (b *LogBuilder) Debugf(format string, args ...any)
- func (b *LogBuilder) Error(msg string)
- func (b *LogBuilder) Errorf(format string, args ...any)
- func (b *LogBuilder) Fatal(msg string)
- func (b *LogBuilder) Fatalf(format string, args ...any)
- func (b *LogBuilder) Info(msg string)
- func (b *LogBuilder) Infof(format string, args ...any)
- func (b *LogBuilder) Warn(msg string)
- func (b *LogBuilder) Warnf(format string, args ...any)
- func (b *LogBuilder) With(key string, value any) *LogBuilder
- type LogChannel
- type LogChannelManager
- func (cm *LogChannelManager) ConfigureChannel(name string, opts *LogOptions)
- func (cm *LogChannelManager) ConfigureDefaultChannel(opts *LogOptions)
- func (cm *LogChannelManager) GetChannel(name string) *LogChannel
- func (cm *LogChannelManager) GetChannelLogger(name string) *slog.Logger
- func (cm *LogChannelManager) GetChannelOptions(name string) *LogOptions
- func (cm *LogChannelManager) GetDefaultChannel() *LogChannel
- func (cm *LogChannelManager) GetDefaultLogger() *slog.Logger
- func (cm *LogChannelManager) GetDefaultOptions() *LogOptions
- func (cm *LogChannelManager) IsChannelConfigured(name string) bool
- func (cm *LogChannelManager) ListConfiguredChannels() []string
- func (cm *LogChannelManager) RemoveChannel(name string)
- type LogOptions
- func (o *LogOptions) Color() *LogOptions
- func (o *LogOptions) JSON() *LogOptions
- func (o *LogOptions) NoColor() *LogOptions
- func (o *LogOptions) Pretty() *LogOptions
- func (o *LogOptions) SetLevel(level slog.Level) *LogOptions
- func (o *LogOptions) SetOutput(w io.Writer) *LogOptions
- func (o *LogOptions) SetTrimPrefix(prefix string) *LogOptions
- type Marshaler
- type Options
- type Pointer
- type PointerError
- type PrettyHandler
- type RequiredFieldError
- type Startable
- type Stoppable
- type TypeMismatchError
- type UnbindingError
- type Unmarshaler
- type UnsupportedError
- type ValidationError
Constants ¶
const ( TypeKey = "type" // discriminator key for Dynamic types RefKey = "$ref" // reference key for Pointer types )
Magic string constants for special keys to avoid typos
const ChannelKey = "channel"
Variables ¶
This section is empty.
Functions ¶
func AsType ¶ added in v0.2.0
AsType visits all objects in the container and returns any that can be cast to type T. This enables finding objects by interface or supertype regardless of their registration type.
func Bind ¶
Bind populates the exported fields of target (a pointer to a struct) from the given data map. Keys are matched using either a struct tag `df:"name,required"` (where name overrides the key and the optional "required" flag enforces presence), `df:"-"` to skip a field, or, when no tag is provided, a best-effort snake_case conversion of the field name.
Use Bind when you need to control how the prototype object is allocated. Use New when you just want to allocate a new object to bind off the heap.
supported kinds: - primitives: string, bool, all int/uint sizes, float32/64, time.Duration - pointers to the above - structs and pointers to structs (recursively bound from map[string]any) - slices of the above (slice items are bound from []interface{})
interface types and maps are not supported and will return an error if encountered, except for fields of type Dynamic which are resolved using Options.DynamicBinders.
opts are optional; pass nil or omit to use defaults.
func BindFromJSON ¶
BindFromJSON reads JSON from the specified file path and binds it to the target struct.
func BindFromYAML ¶
BindFromYAML reads YAML from the specified file path and binds it to the target struct.
func ConfigureChannel ¶ added in v0.2.6
func ConfigureChannel(name string, opts *LogOptions)
ConfigureChannel sets a specific logger configuration for a channel
func Get ¶ added in v0.2.0
Get retrieves an object of type T from the container. Returns the object and true if found, or zero value and false if not found.
func GetNamed ¶ added in v0.2.0
GetNamed retrieves a named object of type T from the container. Returns the object and true if found, or zero value and false if not found.
func HasNamed ¶ added in v0.2.0
HasNamed checks if a named object of type T with the given name exists in the container.
func InitLogging ¶ added in v0.2.5
func InitLogging(opts ...*LogOptions)
InitLogging initializes the logging system with the provided options. if no options are provided, uses default options.
func Inspect ¶
func Inspect(source interface{}, opts ...*InspectOptions) (string, error)
Inspect returns a human-readable representation of a struct's resolved state. designed for configuration debugging and validation. secret fields marked with `df:",secret"` are hidden unless ShowSecrets is true.
the output format is a clean, indented pseudo-data structure optimized for readability rather than parseability.
supported types: - primitives: string, bool, all int/uint sizes, float32/64, time.Duration - pointers to the above (nil pointers shown as "<nil>") - structs and pointers to structs (recursively inspected) - slices of the above (shown as numbered lists) - Dynamic interface implementations (shown with their type) - Pointer[T] references (shown with resolved state)
opts are optional; pass nil or omit to use defaults.
func Link ¶
func Link(targets ...interface{}) error
Link resolves all pointer references in the target objects by building a registry of all Identifiable objects and then resolving Pointer fields to their target objects. objects are namespaced by their concrete type to prevent Id clashes between different types.
func Merge ¶
Merge populates the exported fields of an existing target struct from the given data map, preserving any existing field values that are not present in the data. This allows binding partial data to pre-initialized structs with default values.
uses the same field mapping rules as Bind: struct tags, snake_case conversion, etc.
supported kinds are the same as Bind.
opts are optional; pass nil or omit to use defaults.
func MergeFromJSON ¶ added in v0.1.3
MergeFromJSON reads JSON from the specified file path and merges it with the target struct.
func MergeFromYAML ¶ added in v0.1.3
MergeFromYAML reads YAML from the specified file path and merges it with the target struct.
func MustInspect ¶ added in v0.1.4
func MustInspect(source interface{}, opts ...*InspectOptions) string
MustInspect returns a human-readable representation of a struct's resolved state, panicking if an error occurs. see Inspect for full documentation.
func New ¶
New creates and populates a new instance of type T from the given data map. Unlike Bind, which requires a pre-allocated target pointer, New automatically allocates the object and returns a pointer to the populated struct.
Use Bind instead of New when you need to control where and how the target object is instantiated. New just allocates a fresh target off the heap.
Example usage:
type Person struct {
Name string
Age int
}
data := map[string]any{"name": "John", "age": 30}
person, err := New[Person](data)
if err != nil {
// handle error
}
// person is now *Person with Name="John" and Age=30
supported kinds and field mapping rules are the same as Bind.
opts are optional; pass nil or omit to use defaults.
func NewDfHandler ¶ added in v0.2.5
func NewDfHandler(opts *LogOptions) slog.Handler
NewDfHandler creates a handler that supports both pretty and JSON modes
func NewFromJSON ¶ added in v0.1.3
NewFromJSON reads JSON from the specified file path and returns a new instance of type T.
func NewFromYAML ¶ added in v0.1.3
NewFromYAML reads YAML from the specified file path and returns a new instance of type T.
func NewPrettyHandler ¶ added in v0.2.5
func NewPrettyHandler(level slog.Level, options *LogOptions) slog.Handler
NewPrettyHandler creates a new pretty handler - direct port from pfxlog
func NewPrettyHandlerWithChannel ¶ added in v0.2.6
func NewPrettyHandlerWithChannel(level slog.Level, options *LogOptions, channelName string) slog.Handler
NewPrettyHandlerWithChannel creates a pretty handler with an optional channel name
func OfType ¶ added in v0.2.0
OfType retrieves all objects of type T from the container (both singleton and named). Returns a slice containing the singleton (if exists) followed by all named instances.
func ReconfigureChannel ¶ added in v0.2.6
func ReconfigureChannel(name string, opts *LogOptions)
ReconfigureChannel reconfigures an existing channel (alias for ConfigureChannel)
func Remove ¶ added in v0.2.0
Remove removes an object of type T from the container. Returns true if the object was found and removed, false if it didn't exist.
func RemoveChannel ¶ added in v0.2.6
func RemoveChannel(name string)
RemoveChannel removes a channel configuration, causing it to revert to defaults
func RemoveNamed ¶ added in v0.2.0
RemoveNamed removes a named object of type T with the given name from the container. Returns true if the object was found and removed, false if it didn't exist.
func Set ¶ added in v0.2.0
Set registers a singleton object in the container by its type. If an object of the same type already exists, it will be replaced.
func SetAs ¶ added in v0.2.0
SetAs registers a singleton object in the container by the specified type. If an object of the same type already exists, it will be replaced.
func SetNamed ¶ added in v0.2.0
SetNamed registers a named object in the container by its type and name. If an object with the same type and name already exists, it will be replaced.
func Unbind ¶
Unbind converts a struct (or pointer to struct) into a map[string]any honoring the same `df` tags used by Bind: - `df:"name"` overrides the key name - `df:"-"` skips the field - when no tag is provided, the key defaults to snake_case of the field name
pointers to values: if nil, the key is omitted; otherwise the pointed value is emitted. slices, structs, and nested pointers are handled recursively. time.Duration values are emitted as strings using Duration.String() (e.g., "30s"). Interface fields are not supported, except for fields of type `Dynamic` (and slices of `Dynamic`), which are converted via their ToMap() method which now returns (map[string]any, error). Map-typed fields are not supported.
opts are optional; pass nil or omit to use defaults.
func UnbindToJSON ¶
UnbindToJSON converts a struct to map using Unbind, then writes it as JSON to the specified file path.
func UnbindToYAML ¶
UnbindToYAML converts a struct to map using Unbind, then writes it as YAML to the specified file path.
Types ¶
type Application ¶ added in v0.2.0
type Application[C any] struct { Cfg C // configuration object C *Container // dependency injection container Factories []Factory[C] // factories for creating and registering objects }
Application orchestrates the lifecycle of a dependency injection container with configuration. It manages object creation through factories, dependency linking, startup, and shutdown phases.
func NewApplication ¶ added in v0.2.0
func NewApplication[C any](cfg C) *Application[C]
NewApplication creates a new application with the given configuration. The configuration object is automatically registered in the container.
func WithFactory ¶ added in v0.2.0
func WithFactory[C any](a *Application[C], f Factory[C]) *Application[C]
WithFactory adds a factory to the application for fluent configuration. Returns the application to enable method chaining.
func WithFactoryFunc ¶ added in v0.2.1
func WithFactoryFunc[C any](a *Application[C], f func(a *Application[C]) error) *Application[C]
WithFactoryFunc adds a function factory to the application for fluent configuration. Returns the application to enable method chaining.
func (*Application[C]) Build ¶ added in v0.2.0
func (a *Application[C]) Build() error
Build executes all registered factories to create and register objects in the container. Factories are responsible for calling SetAs[T]() to register their created objects.
func (*Application[C]) Configure ¶ added in v0.2.0
func (a *Application[C]) Configure(path string) error
Configure loads additional configuration from a file and merges it with the existing configuration. Supports JSON and YAML file formats based on file extension.
func (*Application[C]) Initialize ¶ added in v0.2.0
func (a *Application[C]) Initialize(configPaths ...string) error
Initialize executes Configure, Build, and Link phases in sequence. Returns on first error without proceeding to subsequent phases.
func (*Application[C]) Link ¶ added in v0.2.0
func (a *Application[C]) Link() error
Link establishes dependencies between objects by calling Link() on all Linkable objects. This phase occurs after Build() to ensure all objects exist before dependency resolution. Returns the first error encountered, which stops the linking process.
func (*Application[C]) Start ¶ added in v0.2.0
func (a *Application[C]) Start() error
Start initializes all Startable objects after linking is complete. Returns the first error encountered, which stops the startup process.
func (*Application[C]) Stop ¶ added in v0.2.0
func (a *Application[C]) Stop() error
Stop shuts down all Stoppable objects for graceful cleanup. Returns the first error encountered, but continues attempting to stop remaining objects.
type BindingError ¶
BindingError represents struct field binding errors
func (*BindingError) Error ¶
func (e *BindingError) Error() string
func (*BindingError) Unwrap ¶
func (e *BindingError) Unwrap() error
type Container ¶ added in v0.2.0
type Container struct {
// contains filtered or unexported fields
}
Container is an application container that manages singletons and objects by type and (optionally) by name.
func NewContainer ¶ added in v0.2.0
func NewContainer() *Container
NewContainer creates and returns a new empty container.
func (*Container) Clear ¶ added in v0.2.0
func (c *Container) Clear()
Clear removes all objects from the container.
func (*Container) Inspect ¶ added in v0.2.0
func (c *Container) Inspect(format InspectFormat) (string, error)
Inspect returns a formatted representation of the container contents. Supports table, JSON, and YAML formats for human and machine consumption.
type ConversionError ¶
ConversionError represents data conversion failures
func (*ConversionError) Error ¶
func (e *ConversionError) Error() string
func (*ConversionError) Unwrap ¶
func (e *ConversionError) Unwrap() error
type Converter ¶
type Converter interface {
// FromRaw converts a raw value (from the data map) to the target type.
// the input can be any type that appears in the data map (string, int, bool, etc.).
FromRaw(raw interface{}) (interface{}, error)
// ToRaw converts a typed value back to a raw value for serialization.
// the output should be a type that can be marshaled (string, int, bool, etc.).
ToRaw(value interface{}) (interface{}, error)
}
Converter defines a bidirectional type conversion interface for custom field types. it allows users to define how their custom types should be converted to/from the raw data.
type DfTag ¶
type DfTag struct {
Name string // external field name override, empty means use default
Required bool // true if field is required during binding
Secret bool // true if field contains sensitive data
Skip bool // true if field should be skipped entirely
}
DfTag holds the parsed values from a `df` struct tag.
type Dynamic ¶
Dynamic fields can be used when the concrete type of a field is selected dynamically through the `type` data provided in the incoming `map` that will be passed to `Bind`. A polymorphic field type.
type Factory ¶ added in v0.2.0
type Factory[C any] interface { Build(a *Application[C]) error }
Factory creates and registers objects in the application container. Implementations should use SetAs[T]() to register created objects with the container.
type FactoryFunc ¶ added in v0.2.1
type FactoryFunc[C any] func(a *Application[C]) error
FactoryFunc is a function type that implements Factory[C]. It allows using raw functions as factories without defining separate types.
func (FactoryFunc[C]) Build ¶ added in v0.2.1
func (f FactoryFunc[C]) Build(a *Application[C]) error
Build implements the Factory interface for FactoryFunc.
type FileError ¶
FileError represents file I/O operation errors
func (*FileError) IsNotFound ¶ added in v0.2.0
IsNotFound checks if the FileError represents a file not found error.
type Identifiable ¶
type Identifiable interface {
GetId() string
}
Identifiable objects can participate in pointer references by providing a unique Id.
type IndexError ¶
IndexError represents errors with array/slice indexing
func (*IndexError) Error ¶
func (e *IndexError) Error() string
func (*IndexError) Unwrap ¶
func (e *IndexError) Unwrap() error
type InspectData ¶ added in v0.2.0
type InspectData struct {
Summary InspectSummary `json:"summary" yaml:"summary"`
Objects []InspectObject `json:"objects" yaml:"objects"`
}
InspectData represents the structured data for container inspection.
type InspectFormat ¶ added in v0.2.0
type InspectFormat string
InspectFormat defines the output format for container inspection.
const ( InspectHuman InspectFormat = "human" InspectJSON InspectFormat = "json" InspectYAML InspectFormat = "yaml" )
type InspectObject ¶ added in v0.2.0
type InspectObject struct {
Type string `json:"type" yaml:"type"`
Storage string `json:"storage" yaml:"storage"`
Name *string `json:"name" yaml:"name"`
Value string `json:"value" yaml:"value"`
}
InspectObject represents a single object in the container for inspection.
type InspectOptions ¶
type InspectOptions struct {
// MaxDepth limits recursion depth to prevent infinite loops.
MaxDepth int
// Indent sets the indentation string (defaults to " ").
Indent string
// ShowSecrets includes secret fields in output when true.
ShowSecrets bool
}
InspectOptions configures inspection behavior.
type InspectSummary ¶ added in v0.2.0
type InspectSummary struct {
Total int `json:"total" yaml:"total"`
Singletons int `json:"singletons" yaml:"singletons"`
Named int `json:"named" yaml:"named"`
}
InspectSummary provides aggregate statistics about the container.
type Linkable ¶ added in v0.2.0
Linkable defines objects that can establish connections to other container objects during the linking phase after all objects have been created.
type Linker ¶
type Linker struct {
// contains filtered or unexported fields
}
Linker encapsulates the linking process, providing enhanced state management and advanced features.
func NewLinker ¶
func NewLinker(opts ...LinkerOptions) *Linker
NewLinker creates a new Linker with optional options. If no options are provided, default options are used.
func (*Linker) ClearCache ¶
func (l *Linker) ClearCache()
ClearCache clears the internal registry cache if caching is enabled.
func (*Linker) Link ¶
Link resolves all pointer references in the target objects by building a registry of all Identifiable objects and then resolving Pointer fields to their target objects. objects are namespaced by their concrete type to prevent Id clashes between different types.
func (*Linker) Register ¶
Register performs phase 1 of linking: collecting all Identifiable objects. This can be used for multi-stage linking where you want to register objects from multiple sources before resolving references.
func (*Linker) ResolveReferences ¶
ResolveReferences performs phase 2 of linking: resolving all pointer references using the collected registry. This can be used after collecting from multiple sources.
type LinkerOptions ¶
type LinkerOptions struct {
// EnableCaching enables registry caching for repeated linking operations
EnableCaching bool
// AllowPartialResolution allows linking to succeed even if some references can't be resolved
AllowPartialResolution bool
}
LinkerOptions configures the behavior of a Linker instance.
type LogBuilder ¶ added in v0.2.5
type LogBuilder struct {
// contains filtered or unexported fields
}
LogBuilder provides a fluent API for contextual logging, allowing attributes to be added before logging messages. preserves pfxlog's builder pattern semantics.
func ChannelLog ¶ added in v0.2.5
func ChannelLog(name string) *LogBuilder
ChannelLog creates a logger with a specific channel attribute for categorizing log entries
func Log ¶ added in v0.2.5
func Log() *LogBuilder
Log returns a general logger builder for adding contextual attributes
func (*LogBuilder) Debug ¶ added in v0.2.5
func (b *LogBuilder) Debug(msg string)
Debug logs a debug message with the accumulated attributes
func (*LogBuilder) Debugf ¶ added in v0.2.5
func (b *LogBuilder) Debugf(format string, args ...any)
Debugf logs a formatted debug message with the accumulated attributes
func (*LogBuilder) Error ¶ added in v0.2.5
func (b *LogBuilder) Error(msg string)
Error logs an error message with the accumulated attributes
func (*LogBuilder) Errorf ¶ added in v0.2.5
func (b *LogBuilder) Errorf(format string, args ...any)
Errorf logs a formatted error message with the accumulated attributes
func (*LogBuilder) Fatal ¶ added in v0.2.5
func (b *LogBuilder) Fatal(msg string)
Fatal logs a fatal error message with the accumulated attributes and exits the program
func (*LogBuilder) Fatalf ¶ added in v0.2.5
func (b *LogBuilder) Fatalf(format string, args ...any)
Fatalf logs a formatted fatal error message with the accumulated attributes and exits the program
func (*LogBuilder) Info ¶ added in v0.2.5
func (b *LogBuilder) Info(msg string)
Info logs an info message with the accumulated attributes
func (*LogBuilder) Infof ¶ added in v0.2.5
func (b *LogBuilder) Infof(format string, args ...any)
Infof logs a formatted info message with the accumulated attributes
func (*LogBuilder) Warn ¶ added in v0.2.5
func (b *LogBuilder) Warn(msg string)
Warn logs a warning message with the accumulated attributes
func (*LogBuilder) Warnf ¶ added in v0.2.5
func (b *LogBuilder) Warnf(format string, args ...any)
Warnf logs a formatted warning message with the accumulated attributes
func (*LogBuilder) With ¶ added in v0.2.5
func (b *LogBuilder) With(key string, value any) *LogBuilder
With adds a key-value pair to the log context and returns a new builder. this allows for fluent chaining of contextual information.
type LogChannel ¶ added in v0.2.6
type LogChannel struct {
Logger *slog.Logger
Options *LogOptions
}
LogChannel represents a configured logging channel with its options and logger
type LogChannelManager ¶ added in v0.2.6
type LogChannelManager struct {
// contains filtered or unexported fields
}
LogChannelManager manages per-channel logging with independent destinations
func NewLogChannelManager ¶ added in v0.2.6
func NewLogChannelManager(defaultOpts *LogOptions) *LogChannelManager
NewLogChannelManager creates a new channel log manager
func (*LogChannelManager) ConfigureChannel ¶ added in v0.2.6
func (cm *LogChannelManager) ConfigureChannel(name string, opts *LogOptions)
ConfigureChannel sets a specific logger configuration for a channel
func (*LogChannelManager) ConfigureDefaultChannel ¶ added in v0.2.6
func (cm *LogChannelManager) ConfigureDefaultChannel(opts *LogOptions)
ConfigureDefaultChannel updates the default options and recreates the default logger
func (*LogChannelManager) GetChannel ¶ added in v0.2.6
func (cm *LogChannelManager) GetChannel(name string) *LogChannel
GetChannel returns the full LogChannel for a specific channel Returns nil if the channel is not configured
func (*LogChannelManager) GetChannelLogger ¶ added in v0.2.6
func (cm *LogChannelManager) GetChannelLogger(name string) *slog.Logger
GetChannelLogger returns a logger for the specified channel
func (*LogChannelManager) GetChannelOptions ¶ added in v0.2.6
func (cm *LogChannelManager) GetChannelOptions(name string) *LogOptions
GetChannelOptions returns a copy of the options for a specific channel Returns nil if the channel is not configured
func (*LogChannelManager) GetDefaultChannel ¶ added in v0.2.6
func (cm *LogChannelManager) GetDefaultChannel() *LogChannel
GetDefaultChannel returns a copy of the default log channel
func (*LogChannelManager) GetDefaultLogger ¶ added in v0.2.6
func (cm *LogChannelManager) GetDefaultLogger() *slog.Logger
GetDefaultLogger returns the default logger
func (*LogChannelManager) GetDefaultOptions ¶ added in v0.2.6
func (cm *LogChannelManager) GetDefaultOptions() *LogOptions
GetDefaultOptions returns a copy of the default log options
func (*LogChannelManager) IsChannelConfigured ¶ added in v0.2.6
func (cm *LogChannelManager) IsChannelConfigured(name string) bool
IsChannelConfigured returns true if the channel has been explicitly configured
func (*LogChannelManager) ListConfiguredChannels ¶ added in v0.2.6
func (cm *LogChannelManager) ListConfiguredChannels() []string
ListConfiguredChannels returns the names of all configured channels
func (*LogChannelManager) RemoveChannel ¶ added in v0.2.6
func (cm *LogChannelManager) RemoveChannel(name string)
RemoveChannel removes a channel configuration, causing it to revert to defaults
type LogOptions ¶ added in v0.2.5
type LogOptions struct {
Level slog.Level
UseJSON bool
UseColor bool
AbsoluteTime bool
StartTimestamp time.Time
TimestampFormat string
TrimPrefix string
Output io.Writer // output destination, defaults to os.Stdout
CustomHandler slog.Handler
// level labels
ErrorLabel string
WarningLabel string
InfoLabel string
DebugLabel string
// colors
TimestampColor string
FunctionColor string
ChannelColor string
FieldsColor string
DefaultFgColor string // used for resetting colors
ErrorColor string
WarningColor string
InfoColor string
DebugColor string
}
LogOptions configures the df logging system, compatible with pfxlog.Options
func DefaultLogOptions ¶ added in v0.2.5
func DefaultLogOptions() *LogOptions
DefaultLogOptions creates a default configuration with sensible defaults
func (*LogOptions) Color ¶ added in v0.2.5
func (o *LogOptions) Color() *LogOptions
Color enables colored output with default color scheme
func (*LogOptions) JSON ¶ added in v0.2.5
func (o *LogOptions) JSON() *LogOptions
JSON enables JSON output format
func (*LogOptions) NoColor ¶ added in v0.2.5
func (o *LogOptions) NoColor() *LogOptions
NoColor disables colored output
func (*LogOptions) Pretty ¶ added in v0.2.5
func (o *LogOptions) Pretty() *LogOptions
Pretty enables pretty-printed output format (default)
func (*LogOptions) SetLevel ¶ added in v0.2.6
func (o *LogOptions) SetLevel(level slog.Level) *LogOptions
SetLevel allows setting the level threshold
func (*LogOptions) SetOutput ¶ added in v0.2.6
func (o *LogOptions) SetOutput(w io.Writer) *LogOptions
SetOutput sets the output destination
func (*LogOptions) SetTrimPrefix ¶ added in v0.2.6
func (o *LogOptions) SetTrimPrefix(prefix string) *LogOptions
SetTrimPrefix sets the function trim prefix
type Options ¶
type Options struct {
// DynamicBinders maps a discriminator string (found under the "type" key in the input map) to a function that
// consumes the full map and returns a concrete value implementing the Dynamic interface.
DynamicBinders map[string]func(map[string]any) (Dynamic, error)
// FieldDynamicBinders allows specifying binder sets per field path. The key is the structured path of the field as
// used internally by Bind, e.g.: "Root.Items" for a slice field, "Root.Nested.Field" for nested fields.
// any array indices in the path are ignored for matching purposes.
// when present for a field, this map takes precedence over DynamicBinders.
FieldDynamicBinders map[string]map[string]func(map[string]any) (Dynamic, error)
// Converters maps Go types to custom converters for type conversion.
// the key is the reflect.Type of the target field, and the value is a Converter
// that handles bidirectional conversion between raw data and the target type.
Converters map[reflect.Type]Converter
}
Options configures binding behavior.
type Pointer ¶
type Pointer[T Identifiable] struct { Ref string `df:"$ref"` Resolved T // internal resolved reference (exported for reflection) }
Pointer represents a reference to an object of type T that implements Identifiable. During binding, the reference is stored as a string. During linking, it's resolved to the actual object.
func (*Pointer[T]) IsResolved ¶
IsResolved returns true if the pointer has been resolved to an actual object.
type PointerError ¶
PointerError represents pointer resolution errors
func (*PointerError) Error ¶
func (e *PointerError) Error() string
func (*PointerError) Unwrap ¶
func (e *PointerError) Unwrap() error
type PrettyHandler ¶ added in v0.2.5
type PrettyHandler struct {
// contains filtered or unexported fields
}
PrettyHandler is a direct port of pfxlog's PrettyHandler for df
func (*PrettyHandler) Handle ¶ added in v0.2.5
Handle implements slog.Handler.Handle - direct port from pfxlog
type RequiredFieldError ¶
RequiredFieldError represents missing required field errors
func (*RequiredFieldError) Error ¶
func (e *RequiredFieldError) Error() string
type Startable ¶ added in v0.2.0
type Startable interface {
Start() error
}
Startable defines objects that require initialization after linking is complete.
type Stoppable ¶ added in v0.2.0
type Stoppable interface {
Stop() error
}
Stoppable defines objects that require cleanup during shutdown.
type TypeMismatchError ¶
TypeMismatchError represents type conversion errors
func (*TypeMismatchError) Error ¶
func (e *TypeMismatchError) Error() string
type UnbindingError ¶
UnbindingError represents struct field unbinding errors
func (*UnbindingError) Error ¶
func (e *UnbindingError) Error() string
func (*UnbindingError) Unwrap ¶
func (e *UnbindingError) Unwrap() error
type Unmarshaler ¶
Unmarshaler allows a type to define its own unmarshalling logic from a map[string]any.
type UnsupportedError ¶
UnsupportedError represents unsupported operation errors
func (*UnsupportedError) Error ¶
func (e *UnsupportedError) Error() string
type ValidationError ¶
ValidationError represents errors in input validation
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
df_01_bindunbind
command
|
|
|
df_02_tags
command
|
|
|
df_03_defaults
command
|
|
|
df_04_fileio
command
|
|
|
df_05_inspect
command
|
|
|
df_06_validation
command
|
|
|
df_07_converters
command
|
|
|
df_08_marshalers
command
|
|
|
df_09_dynamic
command
|
|
|
df_10_field_binders
command
|
|
|
df_11_pointers
command
|
|
|
df_12_advanced_linker
command
|
|
|
df_13_container
command
|
|
|
df_14_logging
command
|