Skip to main content
Lightning uses a trie-based router that resolves routes by HTTP method and path. You register routes on an *Application value returned by lightning.NewApp() or lightning.DefaultApp().

Registering routes

Each HTTP method has a dedicated registration function. Pass the URL pattern as the first argument, then one or more handler functions.
All handler functions have the signature func(*lightning.Context).

Full example

URL parameters

Prefix a path segment with : to make it a named parameter. Lightning captures the segment and makes it available via ctx.Param.

Reading parameters

Wildcard routes

Prefix a path segment with * to match the rest of the URL as a single named value. The wildcard captures everything from that segment to the end of the path, joined with /.
A wildcard segment must be the last segment in a pattern. Putting additional segments after *param has no effect.

Dynamic method registration with AddRoute

When you need to register a route for an HTTP method that is determined at runtime, use app.AddRoute directly.
AddRoute prepends all global middleware registered with app.Use() before the handlers you supply, matching the behaviour of the typed shorthand methods.