charter

module
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT

README

charter

Go apps on Cloudflare Workers: APIs from a contract, server-rendered sites, or both in one Worker.

charter is a Go library and one command. It does not replace the tools that own each job, it drives them:

Job Tool Its file
The Worker: run it, ship it, its bindings wrangler wrangler.jsonc
Go on Workers workers-go go.mod
Components and the dev loop gsx gsx.toml
The browser's files Vite, as gsx init sets it up vite.config.ts

What charter adds: Go runtimes kept between requests (a Worker that answers in a few milliseconds), bindings that also work off Workers so go test and go run . need no Cloudflare, an API's specs, SDKs and MCP tools from its contract, languages (charter intl) and what search engines read (charter seo).

You need

Go and Node. Nothing else: go.mod's toolchain line and package-lock.json pin every tool, on macOS, Linux and Windows. (Docker only to generate SDKs.)

Start

go run github.com/joeblew999/charter/cmd/charter@latest create my-site -from site
cd my-site
go tool charter dev

-from api is the smallest API, -from notes a full one. go tool charter env says what your machine has.

Commands

The commands are Vite+'s, for a Go app on Workers: the same verbs, each driving the tool that owns the job. Run them as go tool charter <command> in the app's folder.

Command What it does
create A new app from a template
install Everything the app pins: npm's packages, Go's modules
dev The loop you work in, on the real runtime. Leave it running
check Everything that can be said without running the app: format, lint, the contract, the languages. --fix writes what it can
fmt, lint The two halves of check, alone
test go test, then the Worker on wrangler dev: its API, the app's own tests, the search-engine audit. test e2e runs a suite; --base <url> tests a deployed Worker
build The messages, the components' Go, the browser's files and the Wasm. wrangler runs it itself
preview The production build on wrangler dev
deploy The D1 migrations, then wrangler deploy: deploy staging
pack What others consume: an SDK from the contract
run <task> Everything that is not a verb: translate, languages, lighthouse, badges, logs, bench, and the app's own tasks. Alone, it lists them
exec <tool> One of the app's tools as it pins it: exec wrangler …, vite, gsx, gsxui
add, remove add locale:de, add ui:dialog, add d1:DB, a Go module, an npm package
update, outdated Every pin, Go's and npm's
upgrade, migrate charter itself to its latest; an older app moved onto this one
staged Format and check what is staged for a commit; staged install makes it the pre-commit hook
cache clean Everything a build wrote, removed
env What this machine has of what an app needs

Before a push: go tool charter check && go tool charter test.

Leave dev running

charter dev is gsx's loop with wrangler as its server and Vite in front, so what you look at is the Workers runtime with wrangler.jsonc's bindings, as in production. Everything else you do in a second terminal reaches the open page by itself, in about three seconds:

You The page
Save Go or a .gsx file rebuilds, restarts the Worker, reloads
Break the build keeps the last version that worked, and says what is wrong
charter add locale:fr, charter run translate, or edit a catalog the language appears, the text changes
charter add ui:badge and use it appears
charter add leaflet and import it in web/ Vite serves it
Change a variable in wrangler.jsonc wrangler reloads

An app

my-app/
  main.go          transport.Run(handler): a Worker on Cloudflare, a plain server with go run .
  wrangler.jsonc   the Worker: name, bindings, variables, environments
  charter.toml     what wrangler has no place for: the contract, SDKs, tests, languages, search engines
  package.json     wrangler (and Vite, for a site)
  go.mod           charter the library, and charter the command as a tool
  api/             an API's contract and handlers
  pages/           a site's gsx components
  locales/         a site's text, a file per language
  ui/              gsxui's components, as gsxui add copies them
  web/             a site's browser files, which Vite builds
  public/          files served as they are (the icon)
  migrations/      D1's *.sql

vite.config.ts is the one file with a TypeScript name: gsx writes it and gsxui edits it by that name. There is no TypeScript of your own to write.

A site in one call

//go:embed dist/.vite/manifest.json
var dist embed.FS

func main() {
	a := &gsxapp.App{Name: "My App", Dist: dist, Pages: []string{"/", "/about"}}
	transport.Run(a.Handler(mux))
}
<html { gsxapp.HTML(ctx)... }>
	<head>
		<gsxapp.Head title={ locales.HomeTitle |> text } description={ locales.HomeDescription |> text }/>
	</head>

That is Vite's files in dev and in production, a URL per language (/about, /de/about) with every alternate in <head>, robots.txt, a sitemap in every language, /healthz, and noindex on previews. charter test then audits the site the way a search engine reads it.

Languages and search engines are two tables of charter.toml:

url = "https://app.example.com"

[intl]                # charter add locale:de writes it
locales = ["en", "de"]
catalogs = "locales"

[seo]                 # the live site is url, above

The library

Every package is at the top: github.com/joeblew999/charter/<name>.

For Packages
Cloudflare from Go transport (run a handler as a Worker), bindings (variables, static assets, rate limits, fetch), d1, hub (Durable Object fan-out), ratelimit
APIs from a contract serve (the standard API), specs, asyncapi, humaworkers (Huma on Workers), mcp, auth, problem, follow (SSE and WebSocket streams)
Sites gsxapp (the one call above), web, fragments, intl and gsxintl (languages), seo and gsxseo (search engines)

Every binding has a stand-in off Workers: d1.Open is SQLite in memory with your migrations applied, a rate limit counts in memory, the hub is in the process, Intl is a local workerd. So one main.go serves both, and go test runs the real SQL.

The rest of the repo: cmd/charter is the command, internal/ its code, worker/ the JavaScript that runs the Go, examples/ three apps.

Examples

Example What it shows
examples/api The smallest API: one route from a contract, its specs, MCP
examples/site An API and its pages in one Worker: gsx, gsxui, htmx 4, Vite, three languages (one right-to-left), search engines, D1, live over SSE
examples/notes A full API: auth, D1, SSE and WebSocket streams, rate limits, SDKs in Go and Python and a command-line client

In this repo: npm install once at the top (the examples share one node_modules), then go tool charter dev or go tool charter check && go tool charter test in an example.

Size

A Worker built with the standard Go compiler is about 4 MB gzipped, for the smallest API and for a site alike. Workers Paid takes 10 MB; Workers Free takes 3 MB, so these do not fit the free plan.

Directories

Path Synopsis
Package asyncapi generates an AsyncAPI 3.0.0 document from a Huma API, the way Huma itself generates OpenAPI: the Go port of ts/src/asyncapi.ts.
Package asyncapi generates an AsyncAPI 3.0.0 document from a Huma API, the way Huma itself generates OpenAPI: the Go port of ts/src/asyncapi.ts.
Package auth is who may call a Huma API, and with what scopes: the contract declares what each operation needs, and one middleware enforces it, so the specs, the SDKs and the server agree.
Package auth is who may call a Huma API, and with what scopes: the contract declares what each operation needs, and one middleware enforces it, so the specs, the SDKs and the server agree.
authtest
Package authtest is an issuer for tests: it serves its keys over HTTP as Cloudflare Access does (/cdn-cgi/access/certs) and as an OpenID Connect issuer does (/.well-known/openid-configuration, /jwks), and signs tokens with them (go-jose, RS256).
Package authtest is an issuer for tests: it serves its keys over HTTP as Cloudflare Access does (/cdn-cgi/access/certs) and as an OpenID Connect issuer does (/.well-known/openid-configuration, /jwks), and signs tokens with them (go-jose, RS256).
Package bindings is a Go Worker's Cloudflare bindings for app code, called from plain net/http handlers, each with what stands in for it off Workers (go test, an ordinary Go server) built in, so app code needs no file per platform.
Package bindings is a Go Worker's Cloudflare bindings for app code, called from plain net/http handlers, each with what stands in for it off Workers (go test, an ordinary Go server) built in, so app code needs no file per platform.
cmd
charter command
Command charter is the one command of a Go app on Cloudflare Workers.
Command charter is the one command of a Go app on Cloudflare Workers.
Package d1 runs statements on a Cloudflare D1 database from a Go Worker.
Package d1 runs statements on a Cloudflare D1 database from a Go Worker.
example module
sdk/go module
examples
notes module
notes-go module
notes/sdk/go module
Package follow is the one way a client receives a live, ordered, gap-free feed (docs/self/streaming.md, rule 3): the Go port of ts/src/follow.ts, with the same tests.
Package follow is the one way a client receives a live, ordered, gap-free feed (docs/self/streaming.md, rule 3): the Go port of ts/src/follow.ts, with the same tests.
Package fragments serves a live feed to browsers as server-sent events, each item rendered by the caller: an HTML fragment for htmx 4's SSE extension, a datastar-patch-elements event for Datastar.
Package fragments serves a live feed to browsers as server-sent events, each item rendered by the caller: an HTML fragment for htmx 4's SSE extension, a datastar-patch-elements event for Datastar.
go module
lib module
Package gsxapp wires a server-rendered site together: the browser's files Vite builds, its languages and how it answers search engines, in one handler and one <head>.
Package gsxapp wires a server-rendered site together: the browser's files Vite builds, its languages and how it answers search engines, in one handler and one <head>.
filters
Package filters is intl as gsx pipeline filters.
Package filters is intl as gsx pipeline filters.
registry
Package registry is a registry of gsx components that an app copies in and then owns, the way gsxui add copies gsxui's (https://ui.gsxhq.dev): each component a gsx template made of gsxui components, with its text already translated and, for one that runs in the browser, the files it loads there.
Package registry is a registry of gsx components that an app copies in and then owns, the way gsxui add copies gsxui's (https://ui.gsxhq.dev): each component a gsx template made of gsxui components, with its text already translated and, for one that runs in the browser, the files it loads there.
screens
Package ui is intl'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, and the time zone and clock dialog.
Package ui is intl'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, and the time zone and clock dialog.
Package gsxseo is charter run search's for a gsx app: Head, the page's <head> as search engines and link previews read it.
Package gsxseo is charter run search's for a gsx app: Head, the page's <head> as search engines and link previews read it.
Package hub is the live signal of a feed: publish an item, and every subscriber gets it.
Package hub is the live signal of a feed: publish an item, and every subscriber gets it.
Package humaworkers runs a Huma API (github.com/danielgtaylor/huma) on Cloudflare Workers:
Package humaworkers runs a Huma API (github.com/danielgtaylor/huma) on Cloudflare Workers:
internal
badge
Package badge draws a small two-part SVG badge, label and value, as README badges look (shields.io's flat style), with no service and no fonts to fetch: charter run search's Lighthouse and audit badges (charter run badges).
Package badge draws a small two-part SVG badge, label and value, as README badges look (shields.io's flat style), with no service and no fonts to fetch: charter run search's Lighthouse and audit badges (charter run badges).
command
Package command is charter's commands for an app: a Go Worker on Cloudflare, laid out as its upstreams document.
Package command is charter's commands for an app: a Go Worker on Cloudflare, laid out as its upstreams document.
command/intl
Package intl is the languages' commands, which charter's verbs and tasks call (add locale:, check, build, run translate, …): an app's languages, from its charter.toml's intl (found up from the working directory).
Package intl is the languages' commands, which charter's verbs and tasks call (add locale:, check, build, run translate, …): an app's languages, from its charter.toml's intl (found up from the working directory).
command/seo
Package seo is charter seo: how a Go web app answers search engines, from its charter.toml's seo (found up from the working directory): the live site audited as Googlebot reads it, Lighthouse on Google's servers, the README's badges, and Google Search Console.
Package seo is charter seo: how a Go web app answers search engines, from its charter.toml's seo (found up from the working directory): the live site audited as Googlebot reads it, Lighthouse on Google's servers, the README's badges, and Google Search Console.
dbcode
Package dbcode is a project's database code, typed, from its schema (migrations/*.sql, the one place the tables are said).
Package dbcode is a project's database code, typed, from its schema (migrations/*.sql, the one place the tables are said).
fern
Package fern is the SDKs, made with Fern from a project's fern/ (its specs and generators.yml): Fern's settings written from the spec and charter.toml's [sdks]; a group generated (Docker) into sdk/out/<group> when fern/ is newer than what made it; proven in its language (Go: build, vet, and Fern's tests against WireMock; TypeScript: typechecked with the TypeScript its SDKs are written for; Python: mypy and its own tests; the CLI, in Rust: built); and the Go SDK a project commits, in sdk/go.
Package fern is the SDKs, made with Fern from a project's fern/ (its specs and generators.yml): Fern's settings written from the spec and charter.toml's [sdks]; a group generated (Docker) into sdk/out/<group> when fern/ is newer than what made it; proven in its language (Go: build, vet, and Fern's tests against WireMock; TypeScript: typechecked with the TypeScript its SDKs are written for; Python: mypy and its own tests; the CLI, in Rust: built); and the Go SDK a project commits, in sdk/go.
intlkit/catalog
Package catalog is an app's message catalogs as charter intl sees them ([intl] catalogs directory: <locale>.toml per shipped locale, ICU MessageFormat, the source locale first): read and checked against the source (Read), compiled for package intl (Generate), and what is left to translate (Locale.Todo).
Package catalog is an app's message catalogs as charter intl sees them ([intl] catalogs directory: <locale>.toml per shipped locale, ICU MessageFormat, the source locale first): read and checked against the source (Read), compiled for package intl (Generate), and what is left to translate (Locale.Todo).
intlkit/js
Package js is intl's JavaScript, which charter build copies into an app:
Package js is intl's JavaScript, which charter build copies into an app:
intlkit/setup
Package setup is charter add locale:<id>: it sets a gsx app up for intl, from its go.mod's directory.
Package setup is charter add locale:<id>: it sets a gsx app up for intl, from its go.mod's directory.
project
Package project reads what charter knows about an app: the Worker from wrangler.jsonc, which wrangler runs and deploys (https://developers.cloudflare.com/workers/wrangler/configuration/), and charter's own settings from an optional charter.toml beside it.
Package project reads what charter knows about an app: the Worker from wrangler.jsonc, which wrangler runs and deploys (https://developers.cloudflare.com/workers/wrangler/configuration/), and charter's own settings from an optional charter.toml beside it.
promise
Package promise waits for JavaScript promises: the one place the Go Worker's own packages do it (hub and d1).
Package promise waits for JavaScript promises: the one place the Go Worker's own packages do it (hub and d1).
reply
Package reply writes a JSON answer, for what the library answers outside Huma: MCP's endpoint and the documents at /.well-known/.
Package reply writes a JSON answer, for what the library answers outside Huma: MCP's endpoint and the documents at /.well-known/.
run
Package run runs what a project's steps run: a program from the folder's packages or the PATH, its output shown or kept, a server started, waited for and stopped around what uses it, and how long each took; and charter's cache, where a step keeps what it may reuse.
Package run runs what a project's steps run: a program from the folder's packages or the PATH, its output shown or kept, a server started, waited for and stopped around what uses it, and how long each took; and charter's cache, where a step keeps what it may reuse.
seokit/pagespeed
Package pagespeed runs Lighthouse on a live page through Google's PageSpeed Insights API: on Google's servers, so no Node and no local Chrome.
Package pagespeed runs Lighthouse on a live page through Google's PageSpeed Insights API: on Google's servers, so no Node and no local Chrome.
seokit/searchconsole
Package searchconsole talks to the Google Search Console API with a service account, standard library only: submit and read sitemaps, and inspect how Google indexed a URL.
Package searchconsole talks to the Google Search Console API with a service account, standard library only: submit and read sitemaps, and inspect how Google indexed a URL.
standard
Package standard is the standard test: what every API charter serves must do, checked on a running API from outside, as a client sees it.
Package standard is the standard test: what every API charter serves must do, checked on a running API from outside, as a client sees it.
version
Package version is the version of charter a binary is: the release's, written in by its build (goreleaser), else the one Go records (go install …@v1.2.3, go tool charter in an app), else a build from a checkout's.
Package version is the version of charter a binary is: the release's, written in by its build (goreleaser), else the one Go records (go install …@v1.2.3, go tool charter in an app), else a build from a checkout's.
Package intl is a gsx app's languages: the runtime's own Intl, written in markup with gsx's own mechanisms.
Package intl is a gsx app's languages: the runtime's own Intl, written in markup with gsx's own mechanisms.
config
Package config reads an app's languages from its charter.toml: [intl], the languages it ships and where their catalogs are.
Package config reads an app's languages from its charter.toml: [intl], the languages it ships and where their catalogs are.
intltest
Package intltest gives go test the Intl a Worker has: intl's js/intl-worker.mjs, with the app's catalogs, on workerd (intl/workerd), set as intl.Runtime.
Package intltest gives go test the Intl a Worker has: intl's js/intl-worker.mjs, with the app's catalogs, on workerd (intl/workerd), set as intl.Runtime.
workerd
Package workerd is intl's Intl outside a Cloudflare Worker: workerd, the Workers runtime, serving intl's js/intl-worker.mjs with the app's catalogs, set as intl.Runtime.
Package workerd is intl's Intl outside a Cloudflare Worker: workerd, the Workers runtime, serving intl's js/intl-worker.mjs with the app's catalogs, set as intl.Runtime.
Package mcp serves a Huma API as an MCP server (Model Context Protocol), the way Huma itself serves it as OpenAPI: every operation is a tool, its input struct is the tool's inputSchema, and a tool call runs the operation's own HTTP handler, so MCP gets the same validation, the same errors and the same code as REST.
Package mcp serves a Huma API as an MCP server (Model Context Protocol), the way Huma itself serves it as OpenAPI: every operation is a tool, its input struct is the tool's inputSchema, and a tool call runs the operation's own HTTP handler, so MCP gets the same validation, the same errors and the same code as REST.
Package problem writes a refusal as RFC 9457 problem details, as Huma writes an operation's (huma.ErrorModel), for what answers outside an operation: an unknown path (404), a method the path lacks (405), /.well-known/.
Package problem writes a refusal as RFC 9457 problem details, as Huma writes an operation's (huma.ErrorModel), for what answers outside an operation: an unknown path (404), a method the path lacks (405), /.well-known/.
Package ratelimit is how often a caller may call a Huma API's operations, beside auth: the contract declares each limit, and one middleware enforces it, so the specs, the SDKs and the server agree.
Package ratelimit is how often a caller may call a Huma API's operations, beside auth: the contract declares each limit, and one middleware enforces it, so the specs, the SDKs and the server agree.
seo
Package seo is how a site answers search engines: Site, the middleware that serves robots.txt, the sitemap and llms.txt, marks what isn't a page noindex and gives every page one address; Sitemap and LLMsTxt, what it serves; and SnippetWidth, how wide Google shows a title.
Package seo is how a site answers search engines: Site, the middleware that serves robots.txt, the sitemap and llms.txt, marks what isn't a page noindex and gives every page one address; Sitemap and LLMsTxt, what it serves; and SnippetWidth, how wide Google shows a title.
audit
Package audit reads a live site as Googlebot does, robots.txt, the sitemap and every page in it, and returns what would keep a page out of Google's index or look wrong in a result: what charter run audit runs, and what an app's own tests run on a local build (Audit), so a page Google couldn't index fails before it ships.
Package audit reads a live site as Googlebot does, robots.txt, the sitemap and every page in it, and returns what would keep a page out of Google's index or look wrong in a result: what charter run audit runs, and what an app's own tests run on a local build (Audit), so a page Google couldn't index fails before it ships.
config
Package config reads how an app answers search engines from its charter.toml: [seo], the live site and how Lighthouse scores it.
Package config reads how an app answers search engines from its charter.toml: [seo], the live site and how Lighthouse scores it.
Package serve serves a charter API the standard way (docs/self/standard.md), so a project gives its contract, its handlers and whom it trusts, and wires nothing itself:
Package serve serves a charter API the standard way (docs/self/standard.md), so a project gives its contract, its handlers and whom it trusts, and wires nothing itself:
Package specs is the body of a spec command: it writes the specs a contract generates to files, for Fern, or checks that the committed files are what the contract gives.
Package specs is the body of a spec command: it writes the specs a contract generates to files, for Fern, or checks that the committed files are what the contract gives.
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.
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.
Package web is net/http helpers for a Go Worker's pages:
Package web is net/http helpers for a Go Worker's pages:

Jump to

Keyboard shortcuts

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