slug

package
v1.10.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package slug derives URL/DNS-safe identifiers from human names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available added in v1.7.0

func Available(name string, exists func(string) (bool, error)) string

Available returns a free handle for name, or "" when name is blank, reduces to nothing, or the lookup fails — the caller then falls back to whatever it derives handles from.

func IsAvailableHandle

func IsAvailableHandle(s string) bool

IsAvailableHandle reports whether s is a valid, non-reserved handle — i.e. it is already in canonical slug form (IsValid) and not in the reserved set. It is the shared gate for user-chosen workspace names and usernames.

func IsReserved

func IsReserved(s string) bool

IsReserved reports whether s is a reserved handle that may not be claimed as a workspace name or username. Comparison is on the canonical (slugified) form.

func IsValid

func IsValid(name string) bool

IsValid reports whether name is already a canonical slug — lowercase alphanumeric with single interior hyphens — i.e. Make is a no-op on it. Used to constrain user-chosen identifiers that become part of the gateway config, so they stay unique and Goma/DNS-safe.

func Make

func Make(name, fallback string) string

Make returns a slug for name, or fallback if it reduces to empty.

func Token

func Token(n int) string

Token returns a random lowercase-alphanumeric string of length n, suitable as a DNS-safe segment of a container or host name. It falls back to a fixed filler only if the system RNG fails, which keeps callers total-length-stable.

func Unique

func Unique(name, fallback string, exists func(string) (bool, error)) (string, error)

Unique returns a slug for name unique under exists (which reports whether a candidate is already taken).

func UniqueAvailable

func UniqueAvailable(name, fallback string, exists func(string) (bool, error)) (string, error)

UniqueAvailable returns a non-reserved slug for name, unique under exists. It is Unique with an extra suffix bump whenever a candidate lands on a reserved handle, so backfills and auto-derivation never produce a reserved handle.

Types

This section is empty.

Jump to

Keyboard shortcuts

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