Requirements
- Go 1.20 or later
Install
Add Lightning to your module usinggo get:
Import
Import Lightning in your Go source files using its full module path:Lightning is powered by fasthttp, a high-performance HTTP library for Go. You don’t need to import fasthttp directly — Lightning wraps it behind its own API.
Create an application
Lightning provides two constructors. Choose the one that fits your needs:DefaultApp()
DefaultApp() creates an application with two middleware functions pre-registered:
- Logger — logs each request’s method, path, status code, duration, and remote address
- Recovery — catches panics in handlers and returns a 500 response instead of crashing the server
NewApp()
NewApp() creates a bare application with no middleware. Use this when you want full control over what runs on every request, or when you are building a library on top of Lightning:
*lightning.Config to either constructor to customize the application:
Minimal working example
:6789. See the Quick start guide for the full walkthrough.