> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lightning-go.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction

> Lightning is a lightweight, high-performance web framework for Go. Build fast HTTP services with trie-based routing, composable middleware, and an expressive context API.

Lightning is a Go web framework built for speed and simplicity. It wraps [fasthttp](https://github.com/valyala/fasthttp) to deliver high-throughput HTTP handling while keeping the developer API clean and easy to reason about.

You register routes, attach middleware, and write handlers — Lightning takes care of the rest.

## Key features

* **Trie-based routing** — route matching uses a prefix tree for consistent O(k) performance regardless of how many routes you register
* **Middleware** — attach global or route-level middleware using the same `func(*Context)` signature as handlers
* **Route groups** — organize related routes under a shared prefix and apply scoped middleware to the whole group
* **Rich context API** — read URL parameters, query strings, headers, cookies, and request bodies; write JSON, XML, HTML, plain text, or file responses — all from a single `*Context` object
* **Multiple response formats** — `ctx.JSON()`, `ctx.XML()`, `ctx.Text()`, `ctx.HTML()`, `ctx.File()`, `ctx.Success()`, and `ctx.Fail()` cover the common cases without any extra setup
* **Built-in Logger and Recovery middleware** — `DefaultApp()` ships with request logging and panic recovery out of the box
* **Graceful shutdown** — `app.RunGraceful()` listens for `SIGINT`/`SIGTERM` and drains active connections before exiting
* **Static file serving** — serve an entire directory tree with a single `app.Static()` call

## Hello world

```go theme={null}
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 the server and hit the endpoint:

```bash theme={null}
go run main.go
curl http://127.0.0.1:6789/ping
# {"message":"pong"}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Quick start" icon="rocket" href="/quickstart">
    Build and run your first Lightning app in minutes
  </Card>

  <Card title="Routing" icon="route" href="/concepts/routing">
    Learn URL parameters, wildcards, and route registration
  </Card>

  <Card title="Middleware" icon="layer-group" href="/concepts/middleware">
    Add logging, recovery, auth, and more to your handlers
  </Card>

  <Card title="Context API" icon="code" href="/concepts/context">
    Access request data and write responses with the Context object
  </Card>
</CardGroup>
