Start Here
Getting Started
Run the sample application and follow a request from the router to an HTML response.
Prerequisites
GoLazy currently targets Go 1.26 or later. Confirm your installation:
go version
Begin with the
sample_app repository.
Install the CLI and create an app
Install the GoLazy command:
go install github.com/golazy/lazy@latest
Create a new application from the matching sample_app tag:
lazy new github.com/guillermo/my_app
The command clones the v0.1.2 sample app template, removes its Git history,
renames sample_app references to your module path, runs go mod tidy, and
verifies the generated application with go test ./....
Run the application
From the sample application directory, either use the GoLazy CLI:
lazy
or run the application directly:
go run ./cmd/app
The server listens on :8080 by default. Open
http://localhost:8080 in a browser.
Use ADDR to select another port or address:
ADDR=3000 go run ./cmd/app
ADDR=127.0.0.1:3000 go run ./cmd/app
Follow the startup path
The executable initializes dependencies, creates the framework mux, and draws application routes:
ctx := appinit.Context(context.Background())
mux := lazyroutes.New(ctx)
appinit.Draw(ctx, mux)
This order matters:
Contextinitializes the renderer, services, and public-file handler.lazyroutes.Newcreates anhttp.ServeMuxwith the public fallback.Drawregisters the application's routes on that mux.http.Serverserves the completed handler.
Follow one request
For GET /posts, the resource route binds the posts controller constructor to
its Index action:
lazyroutes.Resources(ctx, mux, posts.New)
Resources derives /posts from PostsController, registers the implemented
REST actions, and creates a new controller for each request. The action loads
data into the controller and renders a view:
func (c *PostsController) Index(
_ http.ResponseWriter,
_ *http.Request,
) error {
c.Set("title", "Posts")
c.Set("posts", c.posts.List())
return c.Render("index")
}
Render("index") resolves:
app/views/posts/index.html.tpl
and composes it with:
app/views/layouts/app.html.tpl
Make a first change
Edit app/views/home/index.html.tpl, restart lazy or go run ./cmd/app, and
reload the home page. Templates are embedded at build time, so a running binary
does not read changed files from disk.
Restart the Go process after changing Go code, templates, embedded content, or public files.
Verify the application
Run the complete test suite:
go test ./...
Before a release, also run:
go test -race ./...
go vet ./...
go build -o /tmp/sample-app ./cmd/app
Continue with Application Structure for a map of the repository.