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

# Go Framework Integration

> Own one generated client in a Go service, pass request contexts to sends, and close the client during graceful shutdown.

The Go package is framework-neutral. Create one generated client for each application process, put it on the service that publishes events, and close it during graceful shutdown. The client is safe for concurrent use and owns bounded connection pools and observer state.

Do not construct a client for every request. Per-request construction discards connection reuse, creates unnecessary dispatch goroutines, and makes shutdown harder to reason about.

## `net/http`

Keep ownership in your application root and pass the client to handlers explicitly:

```go theme={"languages":{"custom":["/languages/repost.json"]}}
type Server struct {
    repost *repostclient.Client
}

func NewServer() (*Server, error) {
    client, err := repostclient.NewClient(repost.ClientOptions{
        Telemetry: otelrepost.Telemetry(),
    })
    if err != nil {
        return nil, err
    }
    return &Server{repost: client}, nil
}

func (s *Server) Close() error {
    return s.repost.Close()
}

func (s *Server) createOrder(w http.ResponseWriter, r *http.Request) {
    input, err := decodeOrderCreated(r.Body)
    if err != nil {
        http.Error(w, "invalid request", http.StatusBadRequest)
        return
    }

    _, err = s.repost.Webhooks.Order.Created(r.Context(), input)
    if err != nil {
        http.Error(w, "event publish failed", http.StatusBadGateway)
        return
    }
    w.WriteHeader(http.StatusAccepted)
}
```

The same pattern works with Chi, Gin, Echo, Fiber, Connect, gRPC services, or background workers. Keep the client on the long-lived service or dependency container. Pass the request or job context to every generated method.

Map `*repost.Error` to your own service response policy. Do not return the event payload or SDK error metadata to an untrusted caller. For queue consumers, use `DeliveryState` and the idempotency key to decide whether to acknowledge, retry, or reconcile.

## Graceful shutdown

Stop accepting work and wait for handlers or workers before closing the client:

1. Mark the service unready and stop accepting new requests or jobs.
2. Ask the HTTP server or worker pool to drain with a bounded context.
3. Call `client.Close()`.
4. Shut down telemetry providers owned by the application.

`Close` rejects new sends, cancels admitted sends, waits for their reservations to settle, drains the active observer callback, and releases owned connections. It is safe to call more than once.

Closing the client before the HTTP server drains cancels sends that active handlers still own. That may be the correct choice when the shutdown deadline expires, but it should be an explicit fallback rather than the normal order.

## Request cancellation and tracing

Passing `r.Context()` connects three lifecycles:

* Client disconnects and server deadlines can cancel the send.
* The runtime stops retry waits and socket work when cancellation is observed.
* The OpenTelemetry bridge uses the active inbound span as the parent of `repost.send`.

The SDK does not install HTTP middleware or global OpenTelemetry providers. Configure those once in your application root.

## Serverless functions

Create the client in package scope or another initialization path that the platform reuses across invocations. Do not create and close it inside every invocation. Pass the invocation context to the generated method so platform deadlines still apply.

Some serverless platforms provide no reliable process-shutdown hook. In that case, reuse the client for the lifetime of the warm process and let process termination release it. When the platform does provide a shutdown hook, call `Close` there.

Each operating-system process owns its own client. If a server forks or starts several worker processes, construct the client after the process boundary rather than sharing sockets created before it.

## Continue

<Columns cols={3} className="gap-y-4">
  <Card title="Observability" icon="activity" href="/docs/send/go/observability" cta="Trace" arrow="true">
    Connect inbound spans and own telemetry-provider shutdown.
  </Card>

  <Card title="Configuration" icon="sliders-horizontal" href="/docs/send/go/configuration" cta="Configure" arrow="true">
    Set process-wide deadlines, connection limits, and admission budgets.
  </Card>

  <Card title="Compatibility & security" icon="shield" href="/docs/send/go/compatibility" cta="Support" arrow="true">
    Review runtime, platform, dependency, and credential boundaries.
  </Card>
</Columns>
