util

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package util provides shared utility functions used across the encoder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatHumanTime added in v0.0.8

func FormatHumanTime(rfc3339 string) string

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

func IsConfigured(values ...string) bool

IsConfigured returns true if all provided values are non-empty.

func NotifyResultf

func NotifyResultf(fn func() error, notifyType string, enabled bool)

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

func SafeClose(closer io.Closer, name string)

SafeClose closes an io.Closer and logs any error that occurs. It safely handles nil closers.

func SafeCloseFunc

func SafeCloseFunc(closer io.Closer, name string) func()

SafeCloseFunc creates a defer-friendly closure for resource cleanup.

func WrapError

func WrapError(operation string, err error) error

WrapError wraps an error with a descriptive operation context.

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

func NewBackoff(initial, max time.Duration) *Backoff

NewBackoff creates a backoff calculator with sensible defaults. The factor defaults to 2.0 (doubling) for exponential backoff.

func (*Backoff) Current added in v0.1.0

func (b *Backoff) Current() time.Duration

Current returns the current delay without advancing.

func (*Backoff) Next added in v0.1.0

func (b *Backoff) Next() time.Duration

Next returns the current delay and advances to the next delay value. It doubles the delay (by default factor of 2.0) up to the maximum.

func (*Backoff) Reset added in v0.1.0

func (b *Backoff) Reset(initial time.Duration)

Reset returns the backoff to the initial delay.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

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.

Jump to

Keyboard shortcuts

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