util

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StationNamePattern matches printable characters excluding control characters.
	StationNamePattern = regexp.MustCompile(`^[^\x00-\x1F\x7F]+$`)

	// StationColorPattern matches hex color format (#RRGGBB).
	StationColorPattern = regexp.MustCompile(`^#[0-9A-Fa-f]{6}$`)

	// EmailPattern validates email address format.
	EmailPattern = regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
)

Shared validation patterns used across config and API validation.

Functions

func CheckPathWritable added in v0.5.0

func CheckPathWritable(path string) error

CheckPathWritable verifies that a directory path exists and is writable.

func DarkenColor added in v0.4.0

func DarkenColor(hex string, percent int) string

DarkenColor darkens a hex color by a percentage (0-100).

func ExtractLastError added in v0.1.5

func ExtractLastError(stderr string) string

ExtractLastError extracts the last meaningful line from stderr output.

func FilenameTime added in v0.7.0

func FilenameTime(filename string) (time.Time, bool)

FilenameTime extracts a timestamp from a filename. Supports: YYYY-MM-DD_HH-MM-SS, YYYY-MM-DD-HH-MM, YYYY-MM-DD.

func FormatDuration added in v0.5.0

func FormatDuration(ms int64) string

FormatDuration formats milliseconds as a human-readable duration string. Shows only the two most relevant units:

  • < 1 minute: "45s"
  • < 1 hour: "12m 34s"
  • < 24 hours: "2h 24m"
  • >= 24 hours: "1d 3h"

func FormatHumanTime added in v0.0.8

func FormatHumanTime(rfc3339 string) string

FormatHumanTime converts an RFC3339 timestamp to human-readable local time format.

func GenerateBrandCSS added in v0.4.0

func GenerateBrandCSS(colorLight, colorDark string) string

GenerateBrandCSS generates CSS custom properties for branding.

func GracefulSignal added in v0.3.0

func GracefulSignal(p *os.Process) error

GracefulSignal attempts graceful process termination.

func HumanTime added in v0.0.8

func HumanTime() string

HumanTime returns the current local time in a human-readable format.

func OldestToKeep added in v0.7.0

func OldestToKeep(days int, now time.Time) time.Time

OldestToKeep returns the oldest timestamp to retain during cleanup. Files older than this should be deleted.

Uses rolling retention: now - (days * 24 hours).

func ResolveFFmpegPath added in v0.4.0

func ResolveFFmpegPath(customPath string) string

ResolveFFmpegPath returns the path to the FFmpeg binary, or empty string if not found.

func ShutdownSignals added in v0.3.0

func ShutdownSignals() []os.Signal

ShutdownSignals returns the signals to listen for graceful shutdown.

func TimeUntilNextHour added in v0.7.0

func TimeUntilNextHour(t time.Time) time.Duration

TimeUntilNextHour returns the duration until the next hour boundary.

func ValidatePath added in v0.5.0

func ValidatePath(field, path string) error

ValidatePath validates a file path for security.

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 provides retry delay calculation with exponential growth.

func NewBackoff added in v0.1.0

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

NewBackoff returns a new Backoff with the given initial and maximum delays.

func (*Backoff) Current added in v0.1.0

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

Current returns the current delay.

func (*Backoff) Next added in v0.1.0

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

Next returns the current delay and advances to the next value.

func (*Backoff) Reset added in v0.1.0

func (b *Backoff) Reset()

Reset restores the delay to its initial value.

Jump to

Keyboard shortcuts

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