previewnames

package
v1.5.18 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package previewnames builds automatic preview host labels (ADR 090). It is pure: no I/O and no store access.

Index

Constants

View Source
const MaxLabelLen = 63

MaxLabelLen is the DNS limit for one label.

Variables

This section is empty.

Functions

func Assign

func Assign(in Input, p Policy, taken func(label string) bool) (string, error)

Assign picks a free label: the base label, then -2, -3 and so on, up to MaxAttempts numbered tries. taken reports labels already owned by an app or a preview. Provider zone records are not checked here.

func DefaultReserved

func DefaultReserved() []string

DefaultReserved mirrors the previews.domain_reserved_labels default.

func Host

func Host(label, domain string) string

Host joins a label and the preview domain, or returns empty when the feature is off.

func Label

func Label(in Input) string

Label returns the base label for a preview, at most 63 characters, with no reserved or collision handling.

func Resolve

func Resolve(stored string, in Input, p Policy, taken func(label string) bool) (string, error)

Resolve keeps a stored label across pushes, even when the style setting changed, and assigns one on first use.

func Slug

func Slug(s string) string

Slug lowercases s and turns runs of other characters into one hyphen.

Types

type Input

type Input struct {
	App    string
	Number int
	Branch string
	Style  Style
}

Input describes one preview.

type NoFreeNameError

type NoFreeNameError struct {
	Base     string
	Attempts int
}

NoFreeNameError reports that every candidate label was taken.

func (*NoFreeNameError) Error

func (e *NoFreeNameError) Error() string

type Policy

type Policy struct {
	Reserved       []string
	DashboardLabel string
	MaxAttempts    int
}

Policy carries the live settings. Reserved lists labels a preview may not take.

type Style

type Style string

Style picks how a preview label is formed.

const (
	StylePR       Style = "pr"
	StyleBranch   Style = "branch"
	StyleReadable Style = "readable"
	// StyleBranchDeploy is for branch deploys only and keeps the -br- infix of the deploy app name.
	StyleBranchDeploy Style = "branch-deploy"
)

Supported styles. pr is the default and matches the label used today.

Jump to

Keyboard shortcuts

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