Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSlug = xerror.InvalidSlugFormat()
ErrInvalidSlug is returned when a slug fails validation
Functions ¶
This section is empty.
Types ¶
type Slug ¶
type Slug string
Slug is a string type that represents a URL-safe identifier for entities. Slugs are lowercase alphanumeric with hyphens, 1-100 characters.
func FromName ¶
FromName generates a slug from a name by lowercasing, replacing separators with hyphens, removing non-alphanumeric characters, and trimming to the max length.
func FromString ¶
FromPgtype creates a Slug from a pgx pgtype.Text value. This is used when receiving values from SQLC-generated code.
func New ¶
New creates a new Slug from a string, validating the format. Returns ErrInvalidSlug if the slug is invalid.
func WithRandomSuffix ¶
WithRandomSuffix appends a random alphanumeric suffix to a base slug.
func (Slug) ValidateOrGenerate ¶
ValidateOrGenerate validates the slug, and if invalid, generates one from the provided source string. If the slug is valid, it is returned as-is. If invalid, a slug is generated from the source string.