render

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package render hosts a compiled single-page application and injects per-route Open Graph and Twitter metadata so links unfurl.

The package is HTTP transport. It performs no data access: an application supplies a Resolver for each route, and how that function obtains its facts is invisible here. A link preview is requested by a crawler holding nothing but a URL, so a resolver should return only what any unauthenticated visitor may see.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Dir                 string
	Files               fs.FS
	Index               string
	Reserved            []string
	Defaults            Meta
	BaseURL             string
	Routes              []Route
	ReportResolverError func(context.Context, error)
}

Config declares a renderer. Exactly one of Dir and Files must be set.

type ErrorCode

type ErrorCode string

ErrorCode is the closed set of render failure classifications.

const (
	CodeConfigInvalid ErrorCode = "RENDER_CONFIG_INVALID"
	CodeBundleMissing ErrorCode = "RENDER_BUNDLE_MISSING"
	CodeIndexInvalid  ErrorCode = "RENDER_INDEX_INVALID"
	CodeRouteInvalid  ErrorCode = "RENDER_ROUTE_INVALID"
)

func CodeOf

func CodeOf(err error) (ErrorCode, bool)

CodeOf reports the classification of a render failure. It recognises wrapped errors and never classifies from message text.

type Link struct {
	Path   string
	Values map[string]string
	Query  url.Values
	URL    string
}

Link is the request material a metadata resolver may read. Values holds the pattern wildcards resolved by http.ServeMux, so a route registered as "/f/{token}" yields Values["token"]. No header is carried: none is meaningful when the caller is a crawler.

type Meta

type Meta struct {
	Title       string
	Description string
	Image       string
	URL         string
	Tags        map[string]string
	Omit        []string
}

Meta is the metadata rendered into the shell for one response. The empty string means unset. Tags override the tags generated from the shorthand fields, and Omit deletes generated tags by name.

type Renderer

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

Renderer serves a bundle and its rendered shell.

func New

func New(config Config) (*Renderer, error)

New validates the configuration, reads and parses the index once, and returns a renderer. Every failure is reported here rather than deferred to the first request.

func (*Renderer) Handler

func (renderer *Renderer) Handler() http.Handler

Handler returns the http.Handler that serves the bundle and its shell.

type Resolver

type Resolver func(ctx context.Context, link Link) (*Meta, error)

Resolver produces the metadata for one matched route. Returning a nil Meta, returning an error, or panicking renders the configured defaults.

type Route

type Route struct {
	Patterns []string
	Resolve  Resolver
}

Route binds one resolver to one or more http.ServeMux path patterns.

Jump to

Keyboard shortcuts

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