Skip to content

1. Create the app

Since v0.3.0

You create the project, run it, and look around.

Create the project

anetos new tracker
cd tracker

anetos new writes a project, downloads its dependencies and generates its views. The project is a Go module named tracker; its packages import each other as tracker/app/models and so on. It pins the anetos tool in go.mod: in the project, run it as go tool anetos.

Run it

Create the database tables the framework needs (sessions, the cache, the queue’s jobs), then start the app:

go run . migrate
go tool anetos dev

Open http://localhost:8080. anetos dev rebuilds and restarts the app when you save a file, and reloads the page in the browser. Leave it running in a terminal of its own for the rest of the tutorial.

Look around

PathHolds
main.gosetup: connects the database, then adds the migrations, cache, queue, events, mailer, storage, scheduler, web server and routes. main calls it, and so do the tests
.envThe settings, for your machine: APP_KEY (a fresh key), DB_DATABASE=database/app.db… It stays out of git; .env.example lists the settings
routes/web.goThe routes: URLs to handlers
app/handlers/home.goThe home page’s handler
views/layout.templ, views/home.templThe page shell (a header with the app’s links) and the home page, as templ components: typed Go functions that render HTML
public/static/app.cssThe styles: Anetos’s starter theme, light and dark, with no build step (Style your app)
locales/en/app.yamlThe home page’s text
database/migrations/Migrations: changes to the database’s tables, in Go
main_test.goA test that requests the home page

go run . help lists the app’s commands: run (the default: the web server, the queue’s workers and the scheduler), migrate, routes:list and more. The CLI reference has the full list of files and commands.

Run the test:

go test ./...

Tests boot the app with an in-memory database, so they don’t touch database/app.db.

Next: 2. Accounts.