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

document

package
v1.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package document is an HTML document as values: what every page of a shell shares (Chrome), what a render may know about the caller (Request), what a handler returned (View), and Document, which puts them together around the body a frame arranged. Render turns the result into bytes.

Nothing here reads a context, a request or a database. The nonce an inline script needs and the tenant a page is served for arrive as values; ui/page is the adapter that reads them off the request and hands the response to kit/httpx. That is what lets a storefront, a mail preview or a test render the same document without linking the router or the storage adapter, and it is why the package gate holds this package to design, ui/css, ui/style, ui/components, ui/components/examples, ui, kit/locale and gomponents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bare

func Bare(body []g.Node) g.Node

Bare is the frame with no navigation: a narrow column of cards.

func Brand

func Brand(c Chrome, r Request) string

Brand is what the page calls the installation: the tenant's name, or the chrome's when the tenant has none.

func Document

func Document(c Chrome, r Request, v View, body g.Node) g.Node

Document renders a whole HTML document: the head from the chrome and the view, and the framed body. It is pure; body is the frame's result.

func InlineScript

func InlineScript(nonce, js string) g.Node

InlineScript is an inline <script> carrying the content security policy nonce of the response it belongs to. A page that must run something before the first paint uses it; every other script is a file under the shell's assets and needs nothing.

The nonce is a parameter because it is the response's, minted by kit/httpx per request: ui/page.InlineScript reads it off the context and calls this. A tag written without one is dropped by the browser and reported in a console nobody is reading, which is why the shape takes the nonce rather than leaving it to be remembered.

func Render

func Render(node g.Node) ([]byte, error)

Render renders a node as a whole HTML document: the doctype, and then the node. Without the doctype a browser parses the page in quirks mode, which is a stylesheet that behaves differently for a reason nobody will find.

func RenderFragment

func RenderFragment(node g.Node) ([]byte, error)

RenderFragment renders a node as itself, with no doctype: a response htmx swaps into a page that is already open.

It is the same content type, because a fragment is HTML. What differs is that the browser is not being asked to make a document out of it, and a doctype in the middle of a page is what a browser does the strangest things with.

func RequestNoticeExamples

func RequestNoticeExamples(signIn string) []examples.Example

RequestNoticeExamples captures the visible content Document serves for request failures. IDs retain the controller's existing notice identities; Stack, Alert and Link keep their shared typed interfaces. The hidden, English-language DOM wrapper remains Document's responsibility. A consumer may include these values in its own export or composition without adding a second notice catalog. These are presentation candidates, not request classification, automatic retry, source persistence or an executable prototype.

signIn is rendered as the recovery link when it is not empty; it is the caller's to have checked. ui/page.RequestNoticeExamples applies the kernel's local-path rule before calling this, so a shell reaches the rule through it.

Types

type Chrome

type Chrome struct {
	// Brand is the name shown when the tenant has none: the document title's
	// suffix and the sidebar's label.
	Brand string
	// Assets is the prefix the shell serves ui.Assets under, e.g. "/admin/assets".
	Assets string
	// Stylesheet is the sheet the shell composed, once, with ui.Compose.
	Stylesheet ui.Sheet
	// Scripts are the controllers a page loads, in order, as file names under
	// Assets + "/js/". A shell lists the kernel's it wants and its own.
	Scripts []string
	// SignIn is where an anonymous visitor to a guarded page is sent, and the
	// route offered for recovery without leaving an unsaved form. Empty means
	// the shell has no sign-in link. Controllers never invent a route.
	//
	// It is a path on this site and nothing else. This package renders what it
	// is given; ui/page checks the value against httpx.LocalPath, the one rule
	// for where a browser may be sent, and clears anything that fails it.
	SignIn string
	// Theme pins data-theme on <html>: a shop is the brand's colour and has no
	// toggle. Empty follows the operating system and the person's own toggle,
	// applied before first paint by an inline snippet the adapter adds.
	Theme string
	// Attrs are further <html> attributes: a client's grain and scrollbar,
	// which the shell's own rules give a meaning to. A lang attribute sets the
	// shell's default document language; View.Language takes precedence.
	Attrs map[string]string
}

Chrome is what every page of one shell has in common.

type Request

type Request struct {
	// Path is the request's own path; a sidebar marks it current.
	Path string
	// Tenant is the display name of the tenant the host resolved to, empty
	// when none did. Brand falls back to the chrome's.
	Tenant string
	// Principal identifies the signed-in caller to the page's own controllers,
	// as the data-principal attribute a form is pinned to. Empty means
	// anonymous, and an anonymous document names nobody.
	Principal string
	// Locale is present when the shell composes Messages: this request's
	// selected content language and formatter.
	Locale *locale.Locale
	// Inline are the nonce-bearing inline scripts this response may run, built
	// by the adapter with InlineScript. A renderer cannot make one: it has no
	// nonce.
	Inline []g.Node
}

Request is what a document may know about the caller, as plain values. The adapter reads them once from the request context; ui/page.Request carries the typed tenant and principal a frame asks the Authorizer about, and projects them to this before the document is rendered.

type View

type View struct {
	Title  string
	Status int
	Bare   bool
	// Sensitive prevents caching and sends no referrer on this document's
	// outgoing requests, including assets loaded before scripts run. Use it
	// for pages carrying password links or other private URL credentials.
	// It does not redact the incoming URL from application or proxy logs.
	Sensitive bool
	// Language is the BCP 47 tag of the rendered copy, such as "pt-PT".
	// Empty uses Chrome.Attrs["lang"], or English when no default is set.
	// The application selects and translates the content; this field only
	// declares its language to the browser and assistive technology.
	Language string
	// Theme pins data-theme on this document over the chrome's, for a page
	// whose theme is the tenant's choice rather than the shell's. A pinned
	// document carries no theme script: the choice is not the visitor's.
	Theme string
	Head  []g.Node
	Body  []g.Node
}

View is one page's content. Status zero is 200. Bare asks for the frame with no navigation — the sign-in screen, shown to somebody who has none yet.

func Fault

func Fault(status int, title, detail, back, backLabel string) View

Fault is the page for a refusal a person can act on: the status text, the detail, and one way back. title is what the status is called — ui/page passes http.StatusText, which this package does not link net/http to say.

Jump to

Keyboard shortcuts

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