Skip to main content
This guide walks you through creating a Lightning app from scratch, registering a route, and verifying the response with curl.
1

Install Lightning

Add Lightning to your Go module:
go get github.com/go-labx/lightning
If you don’t have a module yet, initialize one first:
mkdir myapp && cd myapp
go mod init myapp
go get github.com/go-labx/lightning
2

Create main.go

Create a file named main.go with the following content:
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()
}
DefaultApp() creates a new application with two middleware functions already registered: Logger(), which logs every request, and Recovery(), which catches panics and returns a 500 response. Use NewApp() if you want a bare application with no middleware.
3

Run the server

Start the server:
go run main.go
You should see output similar to:
[lightning-app] INFO Starting application on address `:6789`
Lightning listens on port 6789 by default. You can override this by passing an address to app.Run(), for example app.Run(":8080"), or by setting the PORT environment variable.
4

Test with curl

In a separate terminal, send a request to your running server:
curl http://127.0.0.1:6789/ping
You should receive:
{"message":"pong"}
The server terminal will also print a log line for the request, showing the remote address, method, status code, path, and elapsed time.

What’s next

Now that your app is running, explore the core concepts:
  • Routing — add URL parameters, wildcards, and multiple HTTP methods
  • Middleware — write custom middleware and apply it globally or to specific routes
  • Context API — read request data and send structured responses
  • Route groups — organize routes under shared prefixes with scoped middleware