Help us shape the future of Go! Take the 2026 Go Developer Survey

urlstore

package
v0.135.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConflict = codes.ErrConflict
)
View Source
var ErrInvalidVersionCode = fmt.Errorf("%w: not a version code", codes.ErrInvalid)

ErrInvalidVersionCode refuses what is not a version code.

View Source
var (
	ErrNotFound = codes.ErrNotFound
)

Functions

func Canonical

func Canonical(routes contenturl.Routes, languages []string, language string, link contenturl.Link) (string, bool)

Canonical returns link's canonical path in language (the default when ""), with its slug there; false when link's kind has no route.

func FromContext

func FromContext(ctx context.Context) (contenturl.Decision, bool)

FromContext returns the decision Middleware matched for this request.

func ParseVersionCode

func ParseVersionCode(s string) (contenturl.VersionCode, error)

ParseVersionCode reads a version code with ParseCode's rules.

func Path

func Path(languages []string, language, route string, code contenturl.Code, slug string) string

Path is a content page's path, /{language}/{route}/{code}[/{slug}], under Prefix(languages, language); slug is the caller's decorative path for that language (an entity and a title, "/"-joined). Every path ContentKit answers is built here.

func Prefix

func Prefix(languages []string, language string) string

Prefix is the language of a page asked for in language on a site of languages, its default first: language, else the default. Every content page is under its language; contentkit-ui's languagePrefix mirrors this.

func ValidSlug

func ValidSlug(s string) bool

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

func Versioned

func Versioned(path string, code contenturl.VersionCode) string

Versioned is path with ?v=code selecting a version; "" leaves path as is.

Types

type Options

type Options struct {
	Pool   *pgxpool.Pool
	Schema string // the schema ContentKit's migrations were applied in
	Tenant string
}

Options configures one tenant's Store.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router maps content kinds to the host's routes over a Store.

func NewRouter

func NewRouter(store *Store, opts contenturl.RouterOptions) (*Router, error)

NewRouter validates the options and returns the router.

func (*Router) Decide

func (r *Router) Decide(req *http.Request) (contenturl.Decision, error)

Decide parses the request path, resolves its code and compares the path with the canonical one. A missing language prefix, a wrong route, a non-canonical code spelling, a merged code, a missing or stale slug and a trailing slash all redirect; the query (?v= included) is kept.

func (*Router) Handler

func (r *Router) Handler(guard httpapi.Guard) http.Handler

Handler serves GET /{code}[?lang=xx]: the code's link and canonical path, for clients that hold only a code. Any Crockford spelling resolves; the response carries the canonical code. Unknown and hidden codes are 404 not_found, Gone content 410 gone, malformed codes 400 invalid_request. POST /aliases resolves legacy identifiers the same way, in batches. The engine serves them as the codes route group (/v1/codes).

guard binds each request's actor (the code lookup is public; an editor's draft resolves only for them).

func (*Router) Middleware

func (r *Router) Middleware(next http.Handler) http.Handler

Middleware canonicalizes content page requests (GET and HEAD): a non-canonical path is answered 301 with the canonical path and the query unchanged, Gone content with RouterOptions.Gone, and a canonical path reaches next with the Decision in its context (FromContext) and, when BaseURL is set, a canonical Link header. Other requests pass through.

func (*Router) Path

func (r *Router) Path(link contenturl.Link, language string) (string, bool)

Path returns link's canonical path in language (the default when ""), with its slug there; false when its kind has no route.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is one tenant's content-code registry.

func New

func New(opts Options) (*Store, error)

New validates the options and returns the store.

Links returns the link of each registered reference, keyed by ref.Key(); unregistered references are absent. Use it to render lists.

func (*Store) Resolve

func (s *Store) Resolve(ctx context.Context, cs []contenturl.Code) (map[contenturl.Code]contenturl.Link, error)

Resolve returns the link each code names, following merges to the survivor; a code the tenant does not have is absent. A code not in canonical form is ErrInvalidCode.

func (*Store) ResolveAliases

func (s *Store) ResolveAliases(ctx context.Context, keys []contenturl.AliasKey) ([]*contenturl.AliasMatch, error)

ResolveAliases returns what each alias names, following merges, in keys' order: nil for one the tenant does not have.

func (*Store) Versions

func (s *Store) Versions(ctx context.Context, keys []contenturl.VersionKey) (map[contenturl.VersionKey]string, error)

Versions answers the id of each key's version while it is live (published, past its publication time, its content live), as readers open it; keys naming none are left out.

Jump to

Keyboard shortcuts

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