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

# Go

> Read and evaluate a stored identification, then verify raw-body webhook signatures in your backend.

Read and evaluate a stored identification, then verify raw-body webhook signatures in your backend. This guide uses the supported ShieldLabs package API, not a standalone generated client.

## Before you start

Go 1.23+ and a Private API Key. Use an existing Go module or initialize one with go mod init.

Register and verify the website domain in your [analytics dashboard](https://app.shieldlabs.ai/). Use credentials from the same domain and environment as the browser check. For a fresh account, start with [Quick Start](/quickstart).

## Get your credentials

Copy the domain's **Private API Key** from **Integration > API keys** and store it as `SHIELDLABS_API_KEY` in your server environment. For webhook verification, also set `SHIELDLABS_WEBHOOK_SECRET` from **Integration > Webhooks**. Never expose either secret to the browser.

## Install the SDK

```bash theme={null}
go get github.com/ShieldLabs-ai/shieldlabs-go
```

## Add the integration

Read the identification for a request ID, then evaluate it before creating the account:

```go theme={null}
package main

import (
	"context"
	"log"
	"os"

	shieldlabs "github.com/ShieldLabs-ai/shieldlabs-go"
)

func main() {
	client, err := shieldlabs.NewClient(os.Getenv("SHIELDLABS_API_KEY")) // sec_your_private_key
	if err != nil {
		log.Fatal(err)
	}

	// requestID arrives from your page together with the signup form.
	requestID := "3f2b8c1e-9d4a-4e6b-8a7c-2d1e0f9b6a53"

	// Waits for the verdict with a 10-second budget; nil means "not scored in time".
	ident, err := client.Identifications.Get(context.Background(), requestID, nil)
	if err != nil {
		log.Fatal(err)
	}

	verdict := shieldlabs.EvaluateIdentification(ident, shieldlabs.EvaluateOptions{
		IsReplay: func(requestID string) bool { return alreadyUsed(requestID) },
	})
	if !verdict.OK {
		log.Printf("signup refused: %s", verdict.Reason) // missing, replayed, stale, blocked_band, ...
		return
	}
	log.Printf("signup allowed: risk score %d (%s)", ident.RiskScore, verdict.Band)
}

// alreadyUsed records the request ID in your store and reports whether it was
// there before. One identification authorizes one protected action.
func alreadyUsed(requestID string) bool { return false }
```

Verify and parse webhook deliveries:

```go theme={null}
package main

import (
	"errors"
	"io"
	"log"
	"net/http"
	"os"

	"github.com/ShieldLabs-ai/shieldlabs-go/webhook"
)

func main() {
	http.HandleFunc("POST /webhooks/shieldlabs", handleWebhook)
	log.Fatal(http.ListenAndServe("127.0.0.1:8080", nil))
}

func handleWebhook(w http.ResponseWriter, r *http.Request) {
	body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, 1<<20))
	if err != nil {
		http.Error(w, "cannot read the body", http.StatusBadRequest)
		return
	}
	event, err := webhook.ConstructEvent(body, r.Header.Get(webhook.SignatureHeader),
		os.Getenv("SHIELDLABS_WEBHOOK_SECRET")) // whsec_your_signing_secret
	if errors.Is(err, webhook.ErrSignature) {
		http.Error(w, "invalid signature", http.StatusUnauthorized)
		return
	}
	if err != nil {
		http.Error(w, "invalid payload", http.StatusBadRequest)
		return
	}
	if e, ok := event.(*webhook.IdentificationScoredEvent); ok {
		// Keep this idempotent on the request ID: a later server release
		// retries failed deliveries with identical bytes.
		log.Printf("request %s scored %d (%s)", e.Data.RequestID, e.Data.RiskScore, e.Data.Band())
	}
	w.WriteHeader(http.StatusOK) // answer within one second
}
```

[`examples/nethttp`](https://github.com/ShieldLabs-ai/shieldlabs-go/tree/f1526c5ab2ad5e39c2842d0a790a32a1d39b8a70/examples/nethttp) is a complete `net/http` server with a guarded `POST /signup` and a `POST /webhooks/shieldlabs` receiver.

## Test the complete flow

1. Use the Request ID from a real browser check on the same domain as the Private API Key.
2. Confirm the server retrieves that identification and its Risk Score.
3. Test an invalid or missing ID and an unavailable API: none should be treated as a clean identification.
4. For webhooks, test the original raw body with its signature, then change one byte and confirm rejection.

In-memory replay stores in examples are demonstrations, not shared production storage. Claim accepted IDs atomically in a durable database or cache, enforce freshness, authenticate the action, and check the expected domain and user association. Reading a valid identification alone does not authorize a business action.

## Troubleshooting

* No History row: confirm the registered domain, credential/environment match and that the browser remained open while collectors posted.
* Missing or pending verdict: scoring is asynchronous. The server helper waits within a bounded budget; handle a missing result and API errors explicitly.
* Authentication error: use the Private API Key for History, not a Public Key, Management Secret Key or MCP OAuth token.
* Invalid webhook signature: verify the original raw bytes with the endpoint's full signing secret, before trusting parsed JSON.

## Next steps

* [Runnable example](https://github.com/ShieldLabs-ai/shieldlabs-go/tree/f1526c5ab2ad5e39c2842d0a790a32a1d39b8a70/examples/nethttp)
* [SDK reference and changelog](https://github.com/ShieldLabs-ai/shieldlabs-go)
* [Identification flow](/api/identification-flow)
* [Server API](/api/server-api)
* [Webhook setup](/setup/webhooks)
* [Content Security Policy](/setup/csp)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.