codes

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package codes writes the content-code registry (content_codes) for the packages that own content: contenturl for host content, taxonomy and content for ContentKit's own records. Codes are generated in Postgres (contentkit_content_code), so one generator serves runtime and migrations.

Index

Constants

View Source
const MaxSlug = 80

MaxSlug is the longest slug, in bytes (slugs are ASCII).

Variables

View Source
var (
	ErrInvalid  = errors.New("contenturl: invalid input")
	ErrNotFound = errors.New("contenturl: not found")
	ErrConflict = errors.New("contenturl: conflict")
)

Functions

func Drain

func Drain(rows Rows, err error) error

Drain consumes and closes rows.

func Language

func Language(l string) (string, error)

Language normalizes a slug language key.

func Merge

func Merge(ctx context.Context, q Querier, qs, tenant string, from, into Key) error

Merge makes from's code redirect to into's final code and re-points codes already redirected to from, so every redirect is one hop. ErrNotFound when either has no code; ErrConflict when into already redirects to from.

func Put

func Put(ctx context.Context, q Querier, qs, tenant string, entries []Entry) (map[Key]string, error)

Put assigns a code to every entry without one and sets its slugs, in the caller's transaction; it returns every entry's code. qs is the quoted schema. Code collisions and, under READ COMMITTED, concurrent registrations of the same content are retried; stricter isolation levels report the latter as a serialization failure for the caller to retry.

func Slugify

func Slugify(s string) string

Slugify turns text into a URL slug: NFKD, diacritics dropped, a few letters folded (ß -> ss), apostrophes removed, every other run of non [a-z0-9] one hyphen, at most MaxSlug bytes cut at a word boundary. Text without Latin letters or digits gives "".

func ValidSlug

func ValidSlug(s string) bool

ValidSlug reports whether s is a slug Slugify can produce ("" included).

Types

type Entry

type Entry struct {
	Key
	Slug  string
	Slugs map[string]string
}

Entry is one content record's slugs. Slugs nil keeps the stored per-language slugs; a non-nil map replaces them.

type Key

type Key struct{ Kind, ID string }

Key names content within a tenant.

type PgxQuerier

type PgxQuerier interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

PgxQuerier is a pgx pool, connection or transaction.

type Querier

type Querier interface {
	Query(ctx context.Context, sql string, args ...any) (Rows, error)
}

Querier runs one statement. Every registry statement returns rows.

func Pgx

func Pgx(q PgxQuerier) Querier

Pgx adapts a pgx pool, connection or transaction.

func SQL

func SQL(tx *sql.Tx) Querier

SQL adapts a database/sql transaction (pgx stdlib driver).

type Rows

type Rows interface {
	Next() bool
	Scan(...any) error
	Err() error
	Close()
}

Rows is the row iterator the registry reads.

Jump to

Keyboard shortcuts

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