helpers

package
v0.1.0-beta.26 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildServerURL

func BuildServerURL(normalizedURL string) string

BuildServerURL constructs the full URL for API calls

func Contains

func Contains(s, substr string) bool

func EnsureDir

func EnsureDir(dirPath string) error

EnsureDir creates the directory and any necessary parents with secure permissions.

func EnsureDirWithMode

func EnsureDirWithMode(dirPath string, mode os.FileMode) error

EnsureDirWithMode creates the directory with custom permissions.

func FormatDateString

func FormatDateString(dateString string) (string, error)

FormatDateString formats a date string in a simple, CLI-friendly format similar to Docker and Kubernetes tools (e.g., "2 minutes ago", "3 hours ago", "2 days ago")

func FormatDateStringWithLocation

func FormatDateStringWithLocation(dateString string, loc *time.Location) (string, error)

FormatDateStringWithLocation formats a date string for the specified timezone

func FormatTime

func FormatTime(t time.Time) string

FormatTime formats a time.Time in a simple, CLI-friendly format similar to Docker and Kubernetes tools (e.g., "2 minutes ago", "3 hours ago", "2 days ago")

func FormatTimeWithLocation

func FormatTimeWithLocation(t time.Time, loc *time.Location) string

FormatTimeWithLocation formats a time.Time for the specified timezone

func GetARecord

func GetARecord(host string) (net.IP, error)

GetARecord returns the first A record (IPv4 address) for the provided host. It returns an error if no A record is found.

func GetExternalIP

func GetExternalIP() (net.IP, error)

GetExternalIP queries a public service for this machine's external IPv4. It returns the IP or an error.

func GetTimestampFromDeploymentID

func GetTimestampFromDeploymentID(deploymentID string) (time.Time, error)

GetTimestampFromDeploymentID extracts time.Time from an ULID

func IsValidDomain

func IsValidDomain(domain string) error

func IsValidEmail

func IsValidEmail(email string) bool

func NormalizeServerURL

func NormalizeServerURL(rawURL string) (string, error)

NormalizeServerURL strips protocol and normalizes the server URL for storage

func NormalizeVersion

func NormalizeVersion(version string) string

NormalizeVersion strips the 'v' prefix from version strings for comparison

func Ptr

func Ptr[T any](v T) *T

Ptr is a helper that returns a pointer to the given value. Useful for creating pointers to literals or values in a single expression.

func SafeIDPrefix

func SafeIDPrefix(id string) string

func SanitizeString

func SanitizeString(input string) string

SanitizeString takes a string and sanitizes it for use as a safe identifier. Suitable for HAProxy identifiers (backend names, ACL names), Docker container names, and filenames (when extensions are added separately). Allows alphanumeric characters, hyphens, and underscores. Consecutive disallowed characters are replaced by a single underscore.

func ValidatePort

func ValidatePort(port string) error

ValidatePort checks if a port string is a valid port number (1-65535)

Types

type DebounceFunc

type DebounceFunc func()

DebounceFunc defines the type for the function to be executed after debouncing.

type Debouncer

type Debouncer struct {
	// contains filtered or unexported fields
}

Debouncer manages debouncing calls for different keys.

func NewDebouncer

func NewDebouncer(delay time.Duration) *Debouncer

NewDebouncer creates a new Debouncer.

func (*Debouncer) Debounce

func (d *Debouncer) Debounce(key string, action DebounceFunc)

Debounce schedules or resets the timer for a given key. When the delay expires without subsequent calls for the same key, the action function is executed.

func (*Debouncer) Stop

func (d *Debouncer) Stop()

Stop cancels all pending debounced actions.

Jump to

Keyboard shortcuts

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