charter

module
v0.25.2 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

Copy an example:

go run github.com/joeblew999/charter/cmd/charter@latest new my-app            # the smallest API
go run github.com/joeblew999/charter/cmd/charter@latest new my-site -from site
cd my-app
npm install
go tool charter dev

Commands

go tool charter <command>, in the app's folder:

Command What it does
dev The loop you work in: a save rebuilds and reloads (gsx dev; wrangler dev for an app with no gsx)
build The messages, the components' Go, the browser's files and the Wasm. wrangler runs it itself
preview The Worker as Cloudflare runs it, on wrangler dev
check Everything before a push: format, vet, the specs, go test, the languages, the Worker on wrangler dev
test <suite> One of charter.toml's [test.suites] against the Worker; -base https://… for a deployed one
with <command> A command run with the Worker on wrangler dev, BASE its URL
deploy [env] The D1 migrations, then wrangler deploy
live-test The standard test and [test] live against the deployed Worker
spec An API's OpenAPI and AsyncAPI from its contract, Fern's settings, the queries' Go
sdk An SDK from the specs with Fern
intl … The app's languages: charter intl help
seo … What search engines read: charter seo help
new <dir> A new app from an example

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() {
	s := &site.Site{Name: "My App", Dist: dist, Pages: []string{"/", "/about"}}
	transport.Run(s.Handler(mux))
}
<html { site.HTML(ctx)... }>
	<head>
		<site.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, and noindex on previews. charter check 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 intl init writes it
locales = ["en", "de"]
catalogs = "locales"

[seo]                 # the live site is url, above

The library

Three folders, by what you are building:

Folder Packages
cf/ Cloudflare from Go transport (run a handler as a Worker), bindings (variables, static assets, rate limits, fetch), d1, hub (Durable Object fan-out), ratelimit
api/ APIs from a contract serve (the standard API), specs, asyncapi, humaworkers (Huma on Workers), mcp, auth, problem, follow (SSE and WebSocket streams)
site/ Sites site itself (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, 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, two languages, 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 check 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
api
asyncapi
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.
auth
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.
auth/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).
follow
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.
humaworkers
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:
mcp
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.
problem
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/.
serve
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:
specs
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.
cf
bindings
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.
d1
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.
hub
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.
ratelimit
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.
transport
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.
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.
example module
sdk/go module
examples
notes module
notes-go module
notes/sdk/go module
go module
lib module
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 seo's Lighthouse and audit badges (charter seo 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 seo's Lighthouse and audit badges (charter seo 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 charter intl: an app's languages, from its charter.toml's intl (found up from the working directory).
Package intl is charter intl: 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 intl assets copies into an app:
Package js is intl's JavaScript, which charter intl assets copies into an app:
intlkit/setup
Package setup is charter intl init: it sets a gsx app up for intl, from its go.mod's directory.
Package setup is charter intl init: 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 site 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 site 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>.
fragments
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.
gsxintl/filters
Package filters is intl as gsx pipeline filters.
Package filters is intl as gsx pipeline filters.
gsxintl/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.
gsxintl/screens
Package ui is intl's own screens, which charter intl add 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 intl add 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.
gsxseo
Package gsxseo is charter seo's for a gsx app: Head, the page's <head> as search engines and link previews read it.
Package gsxseo is charter seo's for a gsx app: Head, the page's <head> as search engines and link previews read it.
intl
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.
intl/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.
intl/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.
intl/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.
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.
seo/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 seo 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 seo 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.
seo/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.
web
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