slug

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func FromName(name string) (Slug, error)

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

func FromString(s string) Slug

FromPgtype creates a Slug from a pgx pgtype.Text value. This is used when receiving values from SQLC-generated code.

func New

func New(s string) (Slug, error)

New creates a new Slug from a string, validating the format. Returns ErrInvalidSlug if the slug is invalid.

func WithRandomSuffix

func WithRandomSuffix(base Slug, length int) (Slug, error)

WithRandomSuffix appends a random alphanumeric suffix to a base slug.

func (*Slug) Scan

func (s *Slug) Scan(val any) error

Scan implements the sql.Scanner interface for database operations.

func (Slug) String

func (s Slug) String() string

String returns the string representation of the slug.

func (Slug) ValidateOrGenerate

func (s Slug) ValidateOrGenerate(generateFrom string) (Slug, error)

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.

func (Slug) Value

func (s Slug) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database operations.

Jump to

Keyboard shortcuts

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