hostnames

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package hostnames composes and validates the DNS names served by servd.

Index

Constants

View Source
const MaxDNSLabelLength = 63

MaxDNSLabelLength is the RFC 1035 maximum length of one DNS label.

Variables

This section is empty.

Functions

func ApplyWorktreePrefix

func ApplyWorktreePrefix(base, prefix string) string

ApplyWorktreePrefix prepends prefix as a DNS label when it is non-empty.

func FormatURL

func FormatURL(hostname string, port int, tls bool) string

FormatURL returns an HTTP or HTTPS URL and omits the standard protocol port.

func ParseHostname

func ParseHostname(input, tld string) (string, error)

ParseHostname normalizes input as a subdomain of tld and validates the full resulting hostname.

func ParseHostnames

func ParseHostnames(input string, tlds []string) ([]string, error)

ParseHostnames normalizes input for each configured TLD. If input already ends with a configured TLD, the longest matching suffix is stripped first. Invalid TLD-specific results are skipped while valid results are retained.

func SanitizeLabel

func SanitizeLabel(name string) string

SanitizeLabel converts a name into one valid DNS label. It lowercases, replaces invalid characters with hyphens, collapses repeated hyphens, and truncates labels that exceed the DNS limit.

func TruncateLabel

func TruncateLabel(label string) string

TruncateLabel keeps a DNS label within MaxDNSLabelLength. Truncated labels end with a deterministic six-character SHA-256 suffix to retain uniqueness.

func ValidateLabel

func ValidateLabel(label string) error

ValidateLabel verifies one DNS label.

func ValidateTLD

func ValidateTLD(tld string) error

ValidateTLD verifies an explicitly configured DNS suffix.

Types

type InferredName

type InferredName struct {
	Name   string
	Source string
}

InferredName records a project name and the source from which it was inferred.

func InferProjectName

func InferProjectName(cwd string) (InferredName, error)

InferProjectName finds a usable project name from the nearest package.json, then the Git repository root, then the current directory name.

type WorktreePrefix

type WorktreePrefix struct {
	Prefix string
	Source string
}

WorktreePrefix records the branch-derived prefix for a linked Git worktree.

func DetectWorktreePrefix

func DetectWorktreePrefix(cwd string) (WorktreePrefix, error)

DetectWorktreePrefix returns a prefix for a linked worktree's non-default branch. The main checkout is never prefixed, even when it is on a feature branch. Default branches main and master are not prefixed.

Jump to

Keyboard shortcuts

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