Guide
The tug guide
tug is a web framework for Go apps whose frontend is Inertia.js: Go handlers render React, Vue or Svelte pages with props, with no API in between, and the whole app ships as one binary. This guide goes from a new app to a deployed one. Each package's own documentation, on pkg.go.dev, has the rest of the detail.
- Getting started
install tug, make an app, run it, and add a page and a form.
- Routing and handlers
the App, routes, whole and signed links, groups, middleware, security headers among them, the route that answered, the client's address behind a proxy,
Ctx, files, downloads, streams and events, binding requests, and errors. - Pages
Inertia pages and their props, the root template and its nonce, the props worked out later, shared props, redirects, downloads and events on a page, error pages, Vite, and Inertia's DevTools.
- Server-side rendering
pages rendered on the server for a first visit, by Node beside the app, and package
ssr. - Forms and sessions
validation, rules of the app's own, forms that check each field as it's left, flash messages, sessions, in their cookies or kept on the server, and CSRF.
- Languages
what tug and the app say, in the request's language, from a file for each, package
lang, andtug lang. - Files
uploads, checked by their size and what they are, kept on the app's disk or in S3 with package
storage, and links to them, public or signed. - Accounts
the auth starter, in SQLite, Postgres or MySQL, its API tokens and notifications, and packages
authandmail, with copies, files and a link to unsubscribe in one click. - Migrations
the database's tables, made and changed by files of SQL, each run once, in order, as the app starts, and by its
migratecommand, withtug migrate newfor the next, and packagemigrate. - Authorization
what a user may do with a thing, package
auth's abilities, a no as a 403 that says why, and what a page's user may do in its props. - Encryption
the app's key, what tug encrypts and signs with it, package
crypt, for the app's own values, and rotating the key. - Background jobs
package
queue, for work that outlasts the request, and runs again when it fails, runs on a schedule, in a time zone too, waits once however often it's asked for, or so many at once or a second, on every instance, and says when it has failed for good, and how each run went. - Cache
package
cache, for what's slow to work out, kept where every instance of the app finds it, and locks for what mustn't run twice at once. - Broadcasting
package
broadcast, events on channels, carried by the app's database to the pages open on every instance, which reload what changed. - TypeScript
the types
tug genwrites from the Go. - Testing
package
tugtest, Inertia's client for Go's tests of an app's pages, forms, uploads and logins,mailtest, for its mail, and its events. - Deployment
one binary, the Dockerfile, the environment, HTTPS served by the app itself, with certificates from Let's Encrypt, the headers that say what a browser may do with the app's pages, a Content-Security-Policy among them, the logs, and metrics.
- The CLI
tug new,tug dev,tug gen,tug routes,tug lang,tug migrate,tug buildandtug key, in full.
The roadmap has how tug was built and the decisions behind it, and the benchmarks what tug costs a request and what an app made with it takes to run, and how that was measured.