Echo API Starter for Go

A small Echo v4 API starter in Go 1.25 for developers who want Echo's router and middleware in a clean layout. It includes a JSON root route, a health check, slog request logs, panic recovery, graceful shutdown and table-driven tests.

by Light CloudREST APIs

Features

  • GET / answers {"message": "Hello from Echo on Light Cloud"} and GET /health answers {"status": "ok"}
  • Echo's RequestLogger writes one log/slog JSON line per request, with method, path, status and duration
  • HandleError runs the error handler before logging, so a 404 or 500 is logged with its real status
  • Echo's Recover middleware turns a panic into a 500; unknown routes get Echo's JSON 404
  • Graceful shutdown on SIGTERM through e.Shutdown, with a 10 second drain, and a 10 second ReadHeaderTimeout
  • Table-driven tests with net/http/httptest for /, /health and an unknown route, no running server needed
  • make run loads .env, make test runs go vet and go test, make build writes a static binary with CGO_ENABLED=0
  • Layout of main.go plus internal/config and internal/server, so routes, handlers and middleware each have a file

Tech stack

What you need

  • Free plan: it runs as a server app, and the Free plan includes 3 server apps
  • To run it locally: Go 1.25 or newer and make
  • No API keys: it starts with nothing to configure

About

The app is split the way Echo apps usually grow: server.New registers middleware and routes, handlers return an error, and Echo's error handler turns that error into a JSON response. main.go only reads PORT, starts the server and waits for a stop signal, so the first thing you change is handlers.go, adding routes such as e.GET("/items/:id", getItem). Light Cloud builds the Go module and runs it as a container listening on PORT, and each push to your copy redeploys it.

FAQ

How do I add a new route in Echo?

Write a handler with the signature func(c echo.Context) error in internal/server/handlers.go and register it in server.New, for example e.GET("/items/:id", getItem). Read the path value with c.Param("id") and reply with return c.JSON(http.StatusOK, item).

How do I return a 404 with a message in Echo?

Return echo.NewHTTPError(http.StatusNotFound, "item not found") from the handler. Echo's default error handler sends it as JSON with that status, and the request logger records the 404.

How do I add CORS to an Echo API?

The template already imports github.com/labstack/echo/v4/middleware, so add e.Use(middleware.CORS()) in server.New. Pass middleware.CORSWithConfig to limit the allowed origins.

Can I host this Echo starter without Light Cloud?

Yes. It is a plain Go module with no Light Cloud code: make build writes bin/server, which runs on any Linux server or in a minimal container image with PORT set.

Is there a free Echo starter template for Go?

Yes. The repository is an MIT-licensed GitHub template, and it runs as a server app on Light Cloud's Free plan, which includes 3 server apps and needs no card.

Price
Free
Framework
Echo · Go
Plan
Free
Updated

Related templates

All rest api starters