Documentation
¶
Overview ¶
Package slug derives URL/DNS-safe identifiers from human names.
Index ¶
- func Available(name string, exists func(string) (bool, error)) string
- func IsAvailableHandle(s string) bool
- func IsReserved(s string) bool
- func IsValid(name string) bool
- func Make(name, fallback string) string
- func Token(n int) string
- func Unique(name, fallback string, exists func(string) (bool, error)) (string, error)
- func UniqueAvailable(name, fallback string, exists func(string) (bool, error)) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Available ¶ added in v1.7.0
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 ¶
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 ¶
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 ¶
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 Token ¶
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 ¶
Unique returns a slug for name unique under exists (which reports whether a candidate is already taken).
func UniqueAvailable ¶
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.