helpers

package
v0.1.0-beta.69 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyIPMatch

func AnyIPMatch(a, b []net.IP) bool

AnyIPMatch reports whether any IP in a equals any IP in b.

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 FilterGlobalUnicastIPs

func FilterGlobalUnicastIPs(ips []net.IP) []net.IP

FilterGlobalUnicastIPs returns only the global unicast addresses from ips, dropping loopback and link-local entries such as /etc/hosts 127.0.1.1 hostname mappings.

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 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 GetLocalIPs

func GetLocalIPs() ([]net.IP, error)

GetLocalIPs returns the global unicast IP addresses (IPv4 and IPv6) assigned to this machine's network interfaces.

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 ResolveDomainDoH

func ResolveDomainDoH(ctx context.Context, domain string) ([]net.IP, error)

ResolveDomainDoH looks up the domain's A records via public DNS-over-HTTPS providers, bypassing /etc/hosts and local resolver caches so the result reflects what public DNS (and ACME validators) see. An empty, non-error result means public DNS has no A records for the domain.

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