helpers

package
v0.1.0-beta.48 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 14 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 FormatBinaryBytes

func FormatBinaryBytes(bytes uint64) string

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 IsLocalhost

func IsLocalhost(serverURL string) bool

IsLocalhost checks if the given server URL refers to the local machine. It handles various formats: with/without port, IPv4, IPv6.

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 RestartCommand

func RestartCommand() string

RestartCommand returns the command to restart haloyd for the detected init system

func RestartService

func RestartService() error

RestartService executes the service restart command

func RestartServiceArgs

func RestartServiceArgs() (string, []string)

RestartServiceArgs returns the command and arguments to restart haloyd

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. Allows alphanumeric characters 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.

type InitSystem

type InitSystem string

InitSystem represents the detected init system type

const (
	InitSystemd  InitSystem = "systemd"
	InitOpenRC   InitSystem = "openrc"
	InitSysVInit InitSystem = "sysvinit"
	InitUnknown  InitSystem = "unknown"
)

func DetectInitSystem

func DetectInitSystem() InitSystem

DetectInitSystem returns the init system used on the current machine

Jump to

Keyboard shortcuts

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