This module is a simple example of a web server using templ
+ htmx
+ tailwind
.
The web server maintains a map of User
s and the frontend allows vistors to
the site to view, create, edit, and destroy Users
.
It is extremely basic and only intended to demonstrate some basic elements of the featured tools.
task
and air
installed(you need
task
becauseair
uses atask
command to build the binary it runs).
air
go run cmd/main.go
task
and air
Assuming you already have Go 1.21+ installed, you can just use the go install
command.
go install github.com/go-task/task/v3/cmd/task@latest
go install github.com/cosmtrek/air@latest
But there are lots of ways to install both.
You don't really need air
and task
, but they are helpful.
go install github.com/go-task/task/v3/cmd/task@latest
go install github.com/cosmtrek/air@latest
But you will need oapi-codegen
+ templ
.
go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest
go install github.com/a-h/templ/cmd/templ@latest
openapi.yaml
paths:
/:
get:
operationId: HomePage
# ...
# ...
# ...
/new/route:
get:
operationId: NewRoute
task
(or look at the relevant commands in the Taskfile.yml
).task api
templ
components.templ newRoute() {
@baseLayout("new route") {
<div>
This is a new page.
</div>
}
}
func (s Server) NewRoute() {
templ.Handler(newRoutePage()).ServeHTTP(w, r)
}
air
and go to localhost:800/new/route
air