Skip to main content

Requirements

  • Go 1.20 or later

Install

Add Lightning to your module using go get:
go get github.com/go-labx/lightning

Import

Import Lightning in your Go source files using its full module path:
import "github.com/go-labx/lightning"
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
This is the recommended starting point for most applications:
app := lightning.DefaultApp()

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:
app := lightning.NewApp()
You can pass an optional *lightning.Config to either constructor to customize the application:
app := lightning.NewApp(&lightning.Config{
    AppName:            "my-service",
    EnableDebug:        true,
    MaxRequestBodySize: 4 * 1024 * 1024, // 4 MB
})

Minimal working example

package main

import "github.com/go-labx/lightning"

func main() {
    app := lightning.DefaultApp()

    app.Get("/ping", func(ctx *lightning.Context) {
        ctx.JSON(lightning.StatusOK, lightning.Map{
            "message": "pong",
        })
    })

    app.Run()
}
Run it:
go run main.go
By default the server listens on :6789. See the Quick start guide for the full walkthrough.