slug

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package slug derives DNS-1123-compatible identifiers from free-text display names, with deterministic collision suffixes.

Index

Constants

View Source
const MaxLen = 63

Variables

This section is empty.

Functions

func From

func From(displayName string) string

From slugifies a free-text display name. Lowercases, replaces runs of non-[a-z0-9] with a single dash, trims leading/trailing dashes, truncates to MaxLen. Returns "" when the input has no usable characters; callers should treat empty as an error.

func Unique

func Unique(base string, exists func(candidate string) bool) string

Unique returns base if exists(base) is false; otherwise base-2, base-3, … until exists returns false. Callers own the uniqueness scope (per-kind index).

func Valid

func Valid(s string) bool

Valid reports whether s is a legal slug (DNS-1123 label, ≤63 chars).

func WithSuffix

func WithSuffix(base string, n int) string

WithSuffix appends "-N" to base, ensuring the result fits in MaxLen by trimming base. N ≥ 2 (callers iterate from 2).

Types

This section is empty.

Jump to

Keyboard shortcuts

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