Documentation
¶
Overview ¶
Package codes writes the content-code registry (content_codes) for the packages that own content: contenturl for host content, groups and content for ContentKit's own records. Codes are generated in Postgres (contentkit_content_code), so one generator serves runtime and migrations.
Index ¶
- Constants
- Variables
- func Drain(rows Rows, err error) error
- func Language(l string) (string, error)
- func Merge(ctx context.Context, q Querier, qs, tenant string, from, into Key) error
- func Put(ctx context.Context, q Querier, qs, tenant string, entries []Entry) (map[Key]string, error)
- func PutAliases(ctx context.Context, q Querier, qs, tenant string, aliases []Alias) error
- func Reserve(ctx context.Context, q Querier, qs, tenant string, keep map[Key]string) error
- func Slugify(s string) string
- func ValidAlias(source, kind, key string) error
- func ValidCode(code string) bool
- func ValidSlug(s string) bool
- type Alias
- type Entry
- type Key
- type PgxQuerier
- type Querier
- type Rows
Constants ¶
const MaxSlug = 80
MaxSlug is the longest slug, in bytes (slugs are ASCII).
Variables ¶
Functions ¶
func Merge ¶
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 PutAliases ¶ added in v0.83.0
PutAliases records aliases in the caller's transaction. An alias is written once: repeating it is a no-op, pointing it at another target (or locator) is ErrConflict, a target without a code ErrNotFound; roll back on any error.
func Reserve ¶ added in v0.83.0
Reserve gives each key the code an import kept, in the caller's transaction, before Put slugs it: a key keeps a code it already has, so a different one is ErrConflict, as is a code another key holds.
func Slugify ¶
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 ValidAlias ¶ added in v0.83.0
ValidAlias checks an alias's source, identifier space and key.
Types ¶
type Alias ¶ added in v0.83.0
Alias is an identifier of another system resolving to a registered key.
type Entry ¶
Entry is one content record's slugs. Slugs nil keeps the stored per-language slugs; a non-nil map replaces them.
type PgxQuerier ¶
PgxQuerier is a pgx pool, connection or transaction.