Skip to content

Development server

Terminalsh
dygo start -watch # rebuild and restart on .go, go.mod, go.sum and .env changes
dygo start -watch ./cmd/api -- -flag value

The new build replaces the running app only when it compiles, so a typo leaves the last good version serving. The old app gets SIGTERM, so shutdown hooks run (killed after 10 s). Tests, hidden directories, vendor and testdata are not watched.

Instead of writing Routes, mark the controller and its methods:

//dygo:controller /notes
//dygo:use auth.Roles("user")
//dygo:import "example.com/shop/auth"
type Controller struct{ svc *Service }
//dygo:get /
func (c *Controller) List(ctx context.Context) ([]Note, error) { ... }
//dygo:get /{id}
//dygo:use openapi.Summary("Get a note")
func (c *Controller) Get(ctx context.Context, in IDIn) (Note, error) { ... }

dygo gen writes dygo_gen.go with the Routes method, choosing dygo.Handle, HandleNoInput or HandleRaw from the parameters. Directives: controller <prefix>, get|post|put|patch|delete|head|options|all <path>, use <route option expression> (on the type for every route, on a method for that route), and import "<path>" for packages that only the directives use (dygo, openapi, meta, validate, interceptors, ratelimit, errs, net/http and time are known). Add //go:generate dygo gen to a file, and run dygo gen -check in CI to catch a stale file. A type with directives must not also have a hand written Routes.