Start Here

Getting Started

Run the sample application and follow a request from the router to an HTML response.

By Guillermo Alvarez

Prerequisites

GoLazy currently targets Go 1.26 or later. Confirm your installation:

go version

Begin with the sample_app repository.

Run the application

From the sample application directory:

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 := routes.New(ctx)
appinit.Draw(ctx, mux)

This order matters:

  1. Context initializes the renderer, services, and public-file handler.
  2. routes.New creates an http.ServeMux with the public fallback.
  3. Draw registers the application's routes on that mux.
  4. http.Server serves the completed handler.

Follow one request

For GET /posts, the route binds a controller constructor to an action:

mux.Handle(
    "GET /posts",
    controller.Bind(
        ctx,
        posts.New,
        (*posts.PostsController).Index,
    ),
)

Bind creates a new controller for the 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 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.