Documentation
¶
Overview ¶
Package util provides shared utility functions used across the encoder.
Index ¶
- func FormatHumanTime(rfc3339 string) string
- func HumanTime() string
- func IsConfigured(values ...string) bool
- func NotifyResultf(fn func() error, notifyType string, enabled bool)
- func RFC3339Now() string
- func SafeClose(closer io.Closer, name string)
- func SafeCloseFunc(closer io.Closer, name string) func()
- func WrapError(operation string, err error) error
- type Backoff
- type ValidationError
- func ValidateMaxLength(field, value string, maxLen int) *ValidationError
- func ValidatePort(field string, port int) *ValidationError
- func ValidateRange(field string, value, min, max int) *ValidationError
- func ValidateRangeFloat(field string, value, min, max float64) *ValidationError
- func ValidateRequired(field, value string) *ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatHumanTime ¶ added in v0.0.8
FormatHumanTime parses an RFC3339 string and returns human-readable format. Returns "unknown" for empty input, or the original string if parsing fails.
func HumanTime ¶ added in v0.0.8
func HumanTime() string
HumanTime returns the current UTC time in a human-readable format.
func IsConfigured ¶
IsConfigured returns true if all provided values are non-empty.
func NotifyResultf ¶
NotifyResultf executes a notification function and logs the result.
func RFC3339Now ¶
func RFC3339Now() string
RFC3339Now returns the current UTC time formatted as RFC3339.
func SafeClose ¶
SafeClose closes an io.Closer and logs any error that occurs. It safely handles nil closers.
func SafeCloseFunc ¶
SafeCloseFunc creates a defer-friendly closure for resource cleanup.
Types ¶
type Backoff ¶ added in v0.1.0
type Backoff struct {
// contains filtered or unexported fields
}
Backoff calculates exponential backoff delays with a configurable factor and maximum.
func NewBackoff ¶ added in v0.1.0
NewBackoff creates a backoff calculator with sensible defaults. The factor defaults to 2.0 (doubling) for exponential backoff.
type ValidationError ¶
ValidationError represents a field validation failure.
func ValidateMaxLength ¶
func ValidateMaxLength(field, value string, maxLen int) *ValidationError
ValidateMaxLength checks that a string doesn't exceed max length.
func ValidatePort ¶
func ValidatePort(field string, port int) *ValidationError
ValidatePort checks that a port number is valid (1-65535).
func ValidateRange ¶
func ValidateRange(field string, value, min, max int) *ValidationError
ValidateRange checks that an integer is within bounds.
func ValidateRangeFloat ¶
func ValidateRangeFloat(field string, value, min, max float64) *ValidationError
ValidateRangeFloat checks that a float64 is within bounds.
func ValidateRequired ¶
func ValidateRequired(field, value string) *ValidationError
ValidateRequired checks that a string field is not empty.