# errorgap for Go

See [index.md](./index.md) for API details and the placeholder values (`ERRORGAP_API_KEY`, `ERRORGAP_ENDPOINT`, `ERRORGAP_PROJECT_SLUG`).

SDK source: `github.com/errorgaphq/errorgap-go` · current version: `0.1.0`. Requires Go 1.22+.

## Install

```sh
go get github.com/errorgaphq/errorgap-go
```

## Configure

In `main.go`:

```go
import (
    "context"
    "os"

    errorgap "github.com/errorgaphq/errorgap-go"
)

func main() {
    if err := errorgap.Init(errorgap.Config{
        Endpoint:    os.Getenv("ERRORGAP_ENDPOINT"),
        ProjectSlug: os.Getenv("ERRORGAP_PROJECT_SLUG"),
        APIKey:      os.Getenv("ERRORGAP_API_KEY"),
    }); err != nil {
        panic(err)
    }
    defer errorgap.Close(context.Background())
    // ...
}
```

For net/http servers, wrap the handler with the included middleware:

```go
import "github.com/errorgaphq/errorgap-go/stdhttp"

http.ListenAndServe(":8080", stdhttp.Recover(mux))
```

For background goroutines:

```go
go func() {
    defer errorgap.Recover()
    // ... work ...
}()
```

## Trigger a test error

Add a temporary route:

```go
mux.HandleFunc("/errorgap-test", func(w http.ResponseWriter, r *http.Request) {
    panic("Errorgap test error")
})
```

Make sure the panic goes through the SDK's recover handler.

## Verify

Run the verification curl from [index.md](./index.md) and confirm HTTP 201 with a `group_id`. Then hit `/errorgap-test` and confirm the onboarding screen advances.
