Basics
Basics
- Routing: Map URLs to handlers, group routes under shared prefixes and middleware, name them, and generate URLs from names.
- Handlers and requests: Write handlers that receive typed input, return typed output, and turn errors into proper HTTP responses.
- Render HTML with templ: Write pages as templ components (typed, compiled, escaped by default), share a layout, link to routes by name, serve static files with cache-busting URLs, and add interactivity with the bundled htmx.
- Style your app: A new project looks finished from the first page:
anetos newwrites a small stylesheet, the starter theme, that the generators’ pages use. Change it, replace it, or start without it. - Handle HTML forms: Protect forms against cross-site request forgery, send PUT and DELETE from plain HTML, and show validation errors next to the fields with the submitted values kept.
- Validation: Declare rules on an input struct, get one clear message per field, and add checks of your own.
- Sessions and flash messages: Remember things about a visitor between requests, and show a message once after a redirect.
- Configure your application: Read settings from
.envfiles and the environment into typed Go structs, with defaults, required keys and validation. - Commands: Your application builds to one binary. Its first argument picks what it does: run the app (the default), run only some roles, migrate the database, list the routes, or run commands of your own.
- Test your app: Boot the app in a test, send it requests like a browser or an API client, and check the responses, the session, the database, the jobs, events and email the app sent, and its files, with
anetostest; freeze or move the app’s clock.