Documentation
¶
Overview ¶
Package app runs a Go app as a Cloudflare Worker: its pages, its API, its browser files, its languages and its answers to search engines, in one value.
//go:embed dist/.vite/manifest.json
var dist embed.FS
func main() {
(&app.App{Name: "My App", Dist: dist, Pages: pages.Mount, API: api.Handler()}).Run()
}
and in the layout:
<html { app.HTML(ctx)... }>
<head>
<app.Head title={title} description={description}/>
</head>
What that gives:
- Pages (github.com/jackielii/structpages): Pages is the tree of them, each page a type with its route in the field's tag and a Page component. The tree is the one source of routes: links are { About{} |> url } (structpages.URLFor, in the reader's language), and the pages search engines may index are the tree's GET routes without parameters, and the docs.
- Everything that is no page goes to API.
- Vite (github.com/gsxhq/vite): with charter dev a page loads web/main.js from Vite's dev server and reloads on a save; built, it loads the hashed files of dist/, which Workers Static Assets serve.
- Languages (intl): a URL per language (/about, /de/about), <html lang dir>, the canonical URL and every language's alternate in <head>.
- Search engines (seo): /robots.txt, /sitemap.xml in every language, /llms.txt, noindex on what is no page and on everything in a preview, https only, and one address when the Worker has a domain.
The Worker's variables it reads (wrangler.jsonc's vars): APP_DOMAIN, the canonical host; APP_PREVIEW, set to anything where the site must not be indexed.
A Worker runs on Cloudflare: on wrangler dev locally (go tool charter dev), deployed remotely. Nothing here runs anywhere else; the package compiles for the machine it is written on so that editors and go vet need no setup.
Package transport is what a platform puts around the API's handler so that Go can serve WebSockets: workers-go can't answer an upgrade, and net/http needs a WebSocket library. In both places Go answers the upgrade request with plain HTTP, and an adapter carries it over the socket: worker/websocket.mjs on Cloudflare, Serve natively. Which paths are WebSockets, their input and what they send stay in the Go handler (and so in the contract).
What Go answers a WebSocket upgrade (a GET with `Upgrade: websocket`) with:
- Anything but 2xx: a refusal (401, 422, 426). It is returned as it is, and no socket opens.
- 200 with a body: the feed, a stream of lines. Each line is sent as one text frame (empty lines are padding). The feed only ends when it gave up, so the socket is then closed with 1011.
- 204: there is no feed. The socket stays open until the client closes it.
- The header MessagesHeader set to MessagesPost: the channel takes messages. Each text frame the client sends is given to Go as a POST to the same URL, with the upgrade request's headers (so Go authorizes every message as it did the upgrade), MessageHeader, and the frame as the JSON body. The answer is lines again, each sent as one frame. Messages are handled one at a time, in order. Anything but 2xx closes the socket with 1008. Without the header, what the client sends is ignored.
The limit: on Cloudflare the feed and each message run in Go runtimes of their own (a runtime serves one request at a time), so a message can't change what the feed sends through memory. What must be shared goes through a binding, a Durable Object or a database, as the notes hub does.
Index ¶
- Constants
- func Abilities(r *http.Request) (writes Ability, from string, draws, letters Ability)
- func Allow(w http.ResponseWriter, r *http.Request, methods ...string) bool
- func Body() gsx.Attrs
- func CFJSON(r *http.Request) json.RawMessage
- func Document(ctx context.Context) string
- func Draws(r *http.Request) bool
- func Entry(name string) _gsxrt.Node
- func Flushing(w io.Writer) io.Writer
- func GetOnly(h http.Handler) http.Handler
- func HTML(ctx context.Context) gsx.Attrs
- func Head(title string, description string) _gsxrt.Node
- func Mails(r *http.Request) bool
- func Memo(ctx context.Context) *sync.Map
- func Name(ctx context.Context) string
- func NotFound(what string) error
- func Origin(r *http.Request) string
- func PDF(w http.ResponseWriter, r *http.Request, path string) error
- func Reference(r *http.Request) string
- func Render(w http.ResponseWriter, r *http.Request, page Page) error
- func Request(ctx context.Context) *http.Request
- func Run(http.Handler)
- func Seed(binding cloud.Database, fill func(ctx context.Context, db cloud.DB) error)
- func SeedIsDeployed(ctx context.Context) bool
- func Send(w http.ResponseWriter, r *http.Request, m Message) error
- func Serve(h http.Handler) http.Handler
- func SetErrorPage(page func(status int, message string) gsx.Node)
- func SetThemeEditor(markup, preset string)
- func Short(address string) string
- func Status(status int, message string) error
- func StatusOf(err error) (status int, message string, ok bool)
- func Style(ctx context.Context) string
- func ThemeEditor(preview string) string
- func ThemePreset() string
- func WithCF(r *http.Request, cf CF) *http.Request
- func Words(scopes []Scope) []string
- func WriteHTML(w http.ResponseWriter, b []byte)
- type Ability
- type Android
- type App
- type Auth
- type CF
- type Doc
- type DocGroup
- type DocHeading
- type DocPart
- type DocSection
- type Docs
- type Drawer
- type Fact
- type Message
- type Native
- type Page
- type Recorder
- type Redirect
- type Scope
- type Sender
- type Sent
Constants ¶
const ( // DrawHeader is the answer header that says what the Worker's JavaScript is to have the browser draw. DrawHeader = "X-Charter-Draw" // LetterPath is where a page that was drawn for a message is handed back, and LetterHeader has the message. LetterPath = "/__charter/letter" LetterHeader = "X-Charter-Letter" )
A browser takes a second or more to draw a page, and nothing long holds a Go runtime. So Go does not ask the browser: its answer says what is to be drawn (DrawHeader), and the Worker's own JavaScript, which has the answer next, asks (worker/go.mjs). A PDF is then the answer itself. A message's page is a job on the app's queue: its consumer has the page drawn and hands it back to Go with the message, which Go sends (LetterPath, with the message in LetterHeader; mail.go).
const ( DocumentPDF = "pdf" DocumentLetter = "letter" )
What a page is drawn as: a PDF, or what a message says.
const ( KindWords = "words" KindLetter = "letter" KindPDF = "pdf" )
What a message is: its words, its words and a page it shows, or its words and a page that goes with it as a PDF.
const ( OutcomeQueued = "queued" OutcomeSent = "sent" OutcomeWords = "words" OutcomeFailed = "failed" )
How a message stands: it waits for its page to be drawn, it was sent, it was sent as its words because its page could not be drawn or made a message's, or it was not sent.
const ( WithoutMail = "mail" WithoutDomain = "domain" WithoutBrowser = "browser" WithoutQueue = "queue" )
Why an app cannot: it has no mailer, it has no address to write from (it is under workers.dev), it has no browser, it has no queue for the job.
const DocumentHeader = "X-Charter-Document"
DocumentHeader is the request header that says a page is asked for as a document, and as which.
const InvitePath = "/__charter/invite"
InvitePath is the address of an invitation's link, with its code: ?code=…
const MessageHeader = "X-Websocket-Message"
MessageHeader is set on that POST: it is a frame from the socket. Any other request to a channel's address is the channel's (charter/serve), as in charter-lib.
const MessagesHeader = "X-Websocket-Messages"
MessagesHeader, on the answer to an upgrade, says how the channel takes what the client sends.
const MessagesPost = "post"
MessagesPost: every text frame from the client becomes a POST to the upgrade's URL.
const SeedDeployed = "X-Charter-Seed-Deployed"
SeedDeployed is the header charter sends when the database the seed fills is a deployed one (charter run db:seed --deployed): the Worker still runs on this machine, with that database for its binding.
const SeedPath = "/__charter/seed"
SeedPath is where charter asks a Worker built with its seed to run it.
const ServedHeader = "X-D1-Served"
ServedHeader says, to a request that asks which runtime answered (the header x-go-runtime), who answered each of its statements on D1: "DB APAC primary, DB WEUR replica".
const StyleCookie = "gsxui-style"
StyleCookie is where a reader's choice of gsxui's style is kept: gsxui's theme editor in the app sets it (internal/themes/js/charter.js). A style is in the components' markup, so the Worker has to know it to answer; the rest of a preset is CSS and stays in the browser.
Variables ¶
This section is empty.
Functions ¶
func Abilities ¶ added in v0.90.0
Abilities is what the app answering r can do: write to people (and from which address), draw its pages as PDFs, and send a page as what a message shows or as a PDF with it.
func Allow ¶
Allow reports whether r uses one of methods (GET also allows HEAD). Otherwise it replies 405 with an Allow header and returns false.
func Body ¶ added in v0.61.0
Body is <body>'s attributes (<body class="…" { Body()... }>): a link to another page of the app, and a form, shows the next page with no page load. The document stays (its scripts, its stylesheet, its theme) and htmx puts the next page's body in place of this one's (boost). In place of, not morphed into: a page reached by a link is as that page loaded would be. Morphing keeps the elements both pages have, and with them what a reader did to them: a menu that was open stayed open over the next page, where nothing had opened it and nothing placed it. The body's own attributes come with it (its layout: outerHTML, which htmx does to a body as outerSync, as its Back does), and so do the page's title and <html>'s (its language, the reader's zone: charter/intl). With htmx's preload extension (web/main.js) the request starts when the link is pressed, before the click is done.
It is how the swap of a boosted page is said, and of nothing else: an element with its own hx-get keeps its own swap.
What must be a page load says so: a page whose type has FullLoad() bool (the theme screen, whose script is gsxui's and starts as a document loads), and a link with hx-boost="false" (the language list: following one chooses the language, so it is not asked for on a press). A script that comes with a page needs neither: htmx runs it when it puts the page in place.
func CFJSON ¶
func CFJSON(r *http.Request) json.RawMessage
CFJSON is r's request.cf as JSON (CF's fields), nil without one.
func Document ¶ added in v0.83.0
Document is what the page being rendered is drawn as (DocumentPDF, DocumentLetter), "" for a page in a reader's browser: what the layout screen asks.
func Draws ¶ added in v0.88.0
Draws reports whether the app answering r can draw its pages as documents: it has a browser to draw with (App's Browser).
func Flushing ¶
Flushing sends every write on at once: net/http buffers, and on Workers an answer becomes a stream at its first Flush. A feed's writer (SSE, a channel's lines) writes through it.
func GetOnly ¶
GetOnly wraps h so it answers only GET and HEAD (an http.FileServer answers any method).
func HTML ¶
HTML is <html>'s attributes: the page's language and direction (<html { HTML(ctx)... }>), and what it is drawn as when it is asked for as a document.
func Mails ¶ added in v0.88.0
Mails reports whether the app answering r can write to people: it has a binding to send through (App's Mail) and an address of its own to send from, which is a domain, or a developer's machine, where wrangler keeps what is sent as files.
func Memo ¶ added in v0.40.0
Memo is where what is worked out once for a request is kept until it is answered (who its caller is): nil outside one.
func NotFound ¶ added in v0.36.0
NotFound is Status(404): what a page's Props returns when what was asked for is not there.
func Origin ¶
Origin is the scheme and host the request was made to ("https://app.example.workers.dev", "http://localhost:8787"), for absolute URLs without configuring one. On Workers the request URL is absolute; under standard Go the scheme comes from TLS and X-Forwarded-Proto.
func PDF ¶ added in v0.88.0
PDF answers with the page at a path of the app (with its language's prefix, and its query) as a PDF, for whoever asks. It leaves the whole answer: a handler returns what it returns.
func Reference ¶ added in v0.51.0
Reference is what a request is known by, to quote and to find in the logs: Cloudflare's own id of it (the Cf-Ray header), or on a machine that has none, one made here.
func Render ¶
Render renders page into a buffer and writes it as HTML with a Content-Length. If rendering fails it replies 500 instead and returns the error, so a half-rendered page is never sent.
func Request ¶ added in v0.40.0
Request is the request being answered, for a component that is no page's own (a header that says who is signed in): nil outside one.
func Run ¶
Run is for a Worker. A program built for this machine says so and stops: nothing of charter runs off Cloudflare.
func Seed ¶ added in v0.42.0
Seed registers what fills the app's database for a developer: the rows a new checkout starts with (charter run db:seed; charter dev, on a database it has just made). It is written in db/seed.go, a file that is built only for that (//go:build seed), with the app's own typed queries, and runs in a Worker started on this machine, on the real database binding: a seed is never part of a Worker that is deployed. A deployed database is filled by the same seed, from this machine (charter run db:seed --deployed <worker>): SeedIsDeployed says so.
//go:build seed
func init() { app.Seed(env.DB, func(ctx context.Context, conn cloud.DB) error { … }) }
func SeedIsDeployed ¶ added in v0.45.0
SeedIsDeployed says the seed that is running fills a deployed database, where what a local one may have must not be: a token whose value is written down in the app's code (api.SeedPerson keeps none there).
func Send ¶ added in v0.88.0
Send sends a message from the app's own address. With a page it is a job on the app's queue, and w is the answer the job leaves with: the reader is answered at once, and the message goes when its page has been drawn. An app that draws no pages, or has no queue for the job, sends the message's words.
func SetErrorPage ¶ added in v0.77.0
SetErrorPage is called by the layout screen as the program starts, and by nothing else.
func SetThemeEditor ¶ added in v0.71.0
func SetThemeEditor(markup, preset string)
SetThemeEditor is called by the Go charter check --fix writes beside the theme screen (pages/screens/theme_editor.gen.go), and by nothing else.
func Short ¶ added in v0.90.0
Short is an address with the first letter of its name and its domain: enough to know it by on a page other people see.
func Status ¶ added in v0.37.0
Status is an error with the HTTP status the answer should have: a page that is not there, a request that is refused. A plain error is a 500, logged, with nothing of it shown.
func StatusOf ¶ added in v0.41.0
StatusOf is the status and message of an error made by Status or NotFound: for what answers in another form than a page does (an API's problem document).
func Style ¶ added in v0.72.0
Style is the gsxui style the reader of this request chose in the theme editor, by its name (lyra, maia, ...), or "" for the app's own. The app's components ask it as they render (ui/styles, which charter check --fix writes): a name that is no style of gsxui's renders the app's own.
func ThemeEditor ¶ added in v0.71.0
ThemeEditor is gsxui's theme editor, trusted HTML: gsxui's own, rendered by gsxui's own Go when charter check --fix ran. preview is the page of the app it shows changing as a reader chooses (the app's front page). Empty for an app whose editor has not been written yet (go tool charter check --fix).
func ThemePreset ¶ added in v0.71.0
func ThemePreset() string
ThemePreset is the app's own preset (gsxui.preset.json), as JSON: where the editor starts for a reader who has chosen nothing.
func WithCF ¶
WithCF is r carrying cf as its request.cf: for a test, or a server off Cloudflare that knows where its requests come from. On Cloudflare, worker/go.mjs passes the real one.
func WriteHTML ¶
func WriteHTML(w http.ResponseWriter, b []byte)
WriteHTML writes b as text/html with a Content-Length.
Types ¶
type Ability ¶ added in v0.90.0
Ability is whether an app can do one of the things here, and when it cannot, why (the Without… values).
type Android ¶ added in v0.93.0
Android is an Android app as Google names it: its package name, and the SHA-256 fingerprint of each certificate it is signed with, as keytool prints them ("14:6D:E9:…").
type App ¶
type App struct {
// Name is the site's name, which search results show beside its pages.
Name string
// Dist has Vite's manifest, dist/.vite/manifest.json (//go:embed dist/.vite/manifest.json).
Dist fs.FS
// Pages mounts the page tree, as structpages reads it: a struct whose fields are the pages, each with its route
// in its tag. The app's own package has the call, so that structpages-lint finds the tree:
//
// func Mount(mux structpages.Mux, options ...structpages.Option) (*structpages.StructPages, error) {
// return structpages.Mount(mux, Pages{}, "/", "My App", options...)
// }
//
// nil: an app without pages.
Pages func(mux structpages.Mux, options ...structpages.Option) (*structpages.StructPages, error)
// Args are what the pages' Props and handlers ask for by type, the same for every request (structpages.WithArgs).
Args []any
// RequestArgs make what they ask for by type from the request, once for each request and only when asked
// (structpages.WithRequestArgs): func(*http.Request) (T, error). A binding belongs to the request, so a store
// on D1 is one of these, and a page's Props declares the store instead of opening it.
RequestArgs []any
// API answers everything that is not a page. nil: 404.
API http.Handler
// Docs are the app's docs (docs/*.md, as charter build wrote them), for an app that has them: see Docs.
Docs *Docs
// Auth is who may do what, for an app with people or programs to tell apart: the same one the API's operations
// are checked by (api.Auth). A page, or a group of the tree, says what it needs as an operation of the contract
// does, with a method on its type:
//
// func (Account) Needs() []app.Scope { return []app.Scope{api.Write} } // nil: anyone who is signed in
//
// and every route at or under it is checked before it runs. nil: an app where every page is everyone's.
Auth Auth
// Mail, Browser and Queue are what the app writes to people and draws its pages as documents with (mail.go):
// its send_email binding (env.MAIL), its browser binding (env.BROWSER), and a queue of its own for the jobs
// that drawing a message's page is (env.DOCUMENTS: a queue this Worker consumes, and sends nothing else to).
// Each is optional: without Mail the app writes to no one, without Browser a message is its words and no page
// is a PDF, without Queue a message is its words.
Mail Sender
Browser cloud.Browser
Queue cloud.Queue
// Facts are lines the app adds to the admin screen's overview (charter add screen:admin): what an admin wants to
// know of the app itself, each asked when the page is.
Facts []Fact
// SignIn is the page someone who is not signed in is sent to when a page needs them to be (the sign-in
// screen: screens.SignIn{}), with where they were going in ?return=. nil: such a request is a 401.
SignIn any
// Entry is the Vite entry every page loads. Empty: web/main.js.
Entry string
// Icon is the site's icon. Empty: /favicon.svg (public/favicon.svg).
Icon string
// LLMs writes /llms.txt for the site's origin (seo.LLMsTxt writes the layout); url is a page's address, from
// the tree. nil: none.
LLMs func(origin string, url func(page any) string) string
// Native is the app's own apps for phones, which show its pages in a native shell (Hotwire Native): what the
// Worker says of them, so that the site's passkeys sign in from them too (native.go). nil: none.
Native *Native
// contains filtered or unexported fields
}
App is the app: what it is called, its pages, its API, and Vite's manifest.
func (*App) Options ¶ added in v0.38.0
func (a *App) Options(collect bool) []structpages.Option
Options are the tree's options as the app mounts it: what a test that mounts the tree itself passes, with its own RequestArgs after them, so that it is the same tree. collect: also note which routes are pages search engines may index (the app does, once).
pages.Mount(mux, append((&app.App{}).Options(false), structpages.WithRequestArgs(fake))...)
type Auth ¶ added in v0.40.0
Auth is who may do what: api.Auth, which is what checks the API's operations too. Allow is nil when the request's caller has the scopes; else an error with the status 401 (nobody is signed in) or 403 (someone who may not).
type CF ¶
type CF struct {
Country string `json:"country"` // ISO 3166-1 alpha-2, e.g. "DE"
Region string `json:"region"` // e.g. "Bavaria"
RegionCode string `json:"regionCode"` // ISO 3166-2, e.g. "BY"
City string `json:"city"` // e.g. "Munich"
PostalCode string `json:"postalCode"` //
Continent string `json:"continent"` // e.g. "EU"
Timezone string `json:"timezone"` // IANA, e.g. "Europe/Berlin"
Latitude string `json:"latitude"` //
Longitude string `json:"longitude"` //
Colo string `json:"colo"` // the Cloudflare data center, e.g. "MUC"
ASN int `json:"asn"` // the client's network
IsEUCountry string `json:"isEUCountry"` // "1" in the EU (Cloudflare sends "1" or true), else ""
}
CF is what Cloudflare knows of where a request came from: its request.cf, the fields an app uses. On Cloudflare it is read from workers-go's own request properties (fetch.NewIncomingProperties, which a handler may call itself for the rest); off Workers it is the zero CF, or what a test gave the request with WithCF.
type Doc ¶ added in v0.36.0
type Doc struct {
// Slug is the page's place under /docs: "" for docs/index.md, "pages" for docs/03-pages.md.
Slug string
// Title is the page's first heading, and Description its first paragraph, as a search result shows them.
Title, Description string
// Sections are the page: one from each heading of the second level to the next, as gsxui's own doc pages are
// laid out. Markdown is the page as it was written.
Sections []DocSection
Markdown string
// Headings are the page's sections, for a table of contents.
Headings []DocHeading
// Source is the file, from the app's folder: docs/03-pages.md.
Source string
// Group is the group the docs' front page lists the page in (a line of docs/index.md that is only bold, above
// the list that links to it), "" for a page it lists in none. What charter writes of the app itself is in
// "Reference".
Group string
}
Doc is a page of the docs.
func BuiltDocs ¶ added in v0.39.0
BuiltDocs are the pages charter build wrote from docs/*.md: what the app's docs package calls for its Pages. On a Worker they are beside the Wasm (built is empty, and they are read from where the Worker's entry put them), so a page that is edited is a new Worker without a new build of the Go; anywhere else built is the package's own copy.
type DocGroup ¶ added in v0.68.0
DocGroup is pages of the docs under one name, as the list at the side shows them.
type DocHeading ¶ added in v0.36.0
DocHeading is a section of a Doc: the id its heading has in the HTML, and how deep it is (2 or 3).
type DocPart ¶ added in v0.73.0
DocPart is a run of a page's HTML, or a table of it: its head and its rows, each cell's HTML. All of it is trusted: written by charter build from the app's own Markdown, which Markdown is. A table is data so that the docs screen shows it with gsxui's own Table.
type DocSection ¶ added in v0.73.0
type DocSection struct {
Parts []DocPart
}
DocSection is a part of a page under one heading.
type Docs ¶ added in v0.37.0
type Docs struct {
// Name is what the docs are of, and Summary one line about it: the heading of the pages, and of /llms.txt.
Name, Summary string
// Pages are the docs, as charter build wrote them: index.md first.
Pages []Doc
// Repo is the repository on GitHub (https://github.com/owner/name), and Dir the app's folder in it ("" at its
// top): where the pages link to, and where "edit this page" goes.
Repo, Dir string
// Agents is what /llms.txt says to a coding agent, in Markdown: which plugin or skill to work with. It may be
// empty.
Agents string
// More are sections of /llms.txt after the docs: the app's own pages, its API.
More []seo.LLMsSection
}
Docs are an app's docs: the Markdown files of its docs/ folder, which charter build turns into Go once (docs/docs.built.go), so that no Markdown code runs on a Worker. An app has them by naming them in its App and mounting the docs screen (charter add screen:docs) in its tree, at /docs:
docs screens.Docs `route:"/docs Docs"`
From that one value come the pages, their place in the sitemap, each page as Markdown (/docs/<page>.md), and what a language model reads: /llms.txt and /llms-full.txt.
func (*Docs) Around ¶ added in v0.68.0
Around is the page before a page and the one after it, in the order the docs are read: nil at either end.
func (*Docs) Edit ¶ added in v0.37.0
Edit is where a page is edited on GitHub, "" when the docs name no repository.
type Drawer ¶ added in v0.88.0
type Drawer interface {
DrawAs(r *http.Request, lasts time.Duration) (authorization string, err error)
}
Drawer is an Auth that says who the app's browser asks as, when it draws a page for whoever makes a request: the value of an Authorization header that is them for as long as lasts, "" for nobody. api.Auth is one.
type Fact ¶ added in v0.49.0
Fact is one line of the admin screen's overview that is the app's own: what it is called, and its value now. A number is shown as the reader's language writes one, a time.Time as a date, anything else as it prints.
type Message ¶ added in v0.88.0
type Message struct {
To, Subject string
// Text is its words: always there, for a mail program that shows no HTML and a reader who chose so.
Text string
// Page is a page of the app, by its path (with its language's prefix and its query), that the message shows.
// "" for a message that is its words.
Page string
// File is the name of a file the page goes with the message as, in place of being what it shows: a PDF
// ("notes.pdf").
File string
}
Message is what an app writes to someone.
type Native ¶ added in v0.93.0
type Native struct {
// IOS is the iOS app as Apple names it: its team ID and its bundle ID, "ABCDE12345.com.example.notes".
IOS string
// Android is the Android app.
Android Android
}
Native is the app's own apps for phones, which show its pages in a native shell (Hotwire Native): what the Worker says of them so that a passkey made on the site signs in from them too, and one made in them on the site. A passkey belongs to the site's domain; a phone lets an app use one only when the domain names that app, in a file at an address Apple and Google ask for:
/.well-known/apple-app-site-association which iOS apps may use the domain's passkeys (webcredentials) /.well-known/assetlinks.json which Android apps may (delegate_permission/common.get_login_creds)
Each is answered only when the app it names is said.
type Page ¶
Page is what Render renders: a gsx node, a templ component, anything that writes itself.
type Recorder ¶ added in v0.90.0
type Recorder interface {
Noted(r *http.Request, sent Sent) int64
Ended(r *http.Request, id int64, outcome, detail string)
}
Recorder is an Auth that keeps a note of what the app writes to people, for whoever runs it (the admin screen's messages): Noted is a message as it sets out, with the note's id (0: none is kept), and Ended is how it ended, or how far it has got. api.Auth is one, for an app with people. What a message said is never noted, and of whom it went to only enough to know it by.
type Redirect ¶ added in v0.37.0
type Redirect struct{ To string }
Redirect is what a handler returns to send the browser somewhere else: not an error, but it takes the error's way out, so nothing has been written. An htmx request gets HX-Location (htmx follows it as a navigation; a 3xx would be followed by the request itself, and its answer swapped into the wrong place), any other a 303.
type Scope ¶ added in v0.64.0
type Scope struct {
// contains filtered or unexported fields
}
Scope is one thing a caller may do, by its word: "write". Who may do what is said in scopes: a role grants some, a page and an operation of the API need some, and the same code compares them (api.Auth).
A scope is a value, declared once where the app says who may do what, and named everywhere else:
var (
Read = charter.NewScope("read")
Write = charter.NewScope("write")
)
func (PostNote) Needs() []charter.Scope { return []charter.Scope{api.Write} }
It is not a string, so that it cannot be written as one: a word typed where a scope is needed (Needs: "wrtie") would compile, name a scope no role grants, and shut everyone out of the page with nothing to say why. A scope that is not declared is a name that does not exist. charter check fails an app that makes one anywhere but in a declaration (its part scopes).
func (Scope) MarshalText ¶ added in v0.64.0
MarshalText and UnmarshalText are the scope as its word, wherever one is written out or read back.
func (Scope) String ¶ added in v0.64.0
String is the scope's word, as a token's and the API's specs have it.
func (*Scope) UnmarshalText ¶ added in v0.64.0
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apptest is for an app's tests of its Worker (the app's test/ folder), which go tool charter test runs against the Worker on wrangler dev, and go tool charter test --deployed against the deployed one.
|
Package apptest is for an app's tests of its Worker (the app's test/ folder), which go tool charter test runs against the Worker on wrangler dev, and go tool charter test --deployed against the deployed one. |
|
Package screens is charter's own screens, which charter add screen:<name> copies into an app the way gsxui add copies components: the language list, the offer of the page in the reader's language, the switch between the light and the dark theme, signing in with a passkey, and the docs' pages.
|
Package screens is charter's own screens, which charter add screen:<name> copies into an app the way gsxui add copies components: the language list, the offer of the page in the reader's language, the switch between the light and the dark theme, signing in with a passkey, and the docs' pages. |