> ## 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.

# Installation

> Add Lightning to your Go project and create your first application instance.

## Requirements

* Go **1.20 or later**

## Install

Add Lightning to your module using `go get`:

```bash theme={null}
go get github.com/go-labx/lightning
```

## Import

Import Lightning in your Go source files using its full module path:

```go theme={null}
import "github.com/go-labx/lightning"
```

<Note>
  Lightning is powered by [fasthttp](https://github.com/valyala/fasthttp), a high-performance HTTP library for Go. You don't need to import fasthttp directly — Lightning wraps it behind its own API.
</Note>

## 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:

```go theme={null}
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:

```go theme={null}
app := lightning.NewApp()
```

You can pass an optional `*lightning.Config` to either constructor to customize the application:

```go theme={null}
app := lightning.NewApp(&lightning.Config{
    AppName:            "my-service",
    EnableDebug:        true,
    MaxRequestBodySize: 4 * 1024 * 1024, // 4 MB
})
```

## Minimal working example

```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 it:

```bash theme={null}
go run main.go
```

By default the server listens on `:6789`. See the [Quick start](/quickstart) guide for the full walkthrough.
