tug v0.45.0

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.

  1. Getting started

    install tug, make an app, run it, and add a page and a form.

  2. 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.

  3. 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.

  4. Server-side rendering

    pages rendered on the server for a first visit, by Node beside the app, and package ssr.

  5. 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.

  6. Languages

    what tug and the app say, in the request's language, from a file for each, package lang, and tug lang.

  7. 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.

  8. Accounts

    the auth starter, in SQLite, Postgres or MySQL, its API tokens and notifications, and packages auth and mail, with copies, files and a link to unsubscribe in one click.

  9. Migrations

    the database's tables, made and changed by files of SQL, each run once, in order, as the app starts, and by its migrate command, with tug migrate new for the next, and package migrate.

  10. 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.

  11. Encryption

    the app's key, what tug encrypts and signs with it, package crypt, for the app's own values, and rotating the key.

  12. 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.

  13. 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.

  14. Broadcasting

    package broadcast, events on channels, carried by the app's database to the pages open on every instance, which reload what changed.

  15. TypeScript

    the types tug gen writes from the Go.

  16. 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.

  17. 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.

  18. The CLI

    tug new, tug dev, tug gen, tug routes, tug lang, tug migrate, tug build and tug 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.

tug