---
title: "Go Backend SDK"
description: "High-performance Go SDK for verifying session tokens, managing organizations, and executing India identity checks."
order: 4
category: "Getting Started"
updated: "2026-10-13"
---

# Go Backend SDK

The official AuthSetu Go SDK allows you to verify JWT session tokens, interact with the AuthSetu REST API, and issue Indian identity verification requests directly from your Go microservices.

## Installation

```bash
go get github.com/authsetu/authsetu/sdks/go
```

## Initializing the Client

```go
package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"github.com/authsetu/authsetu/sdks/go/client"
)

func main() {
	c, err := client.NewClient(&client.Config{
		SecretKey: "sk_live_sample12345",
		BaseURL:   "https://api.authsetu.com",
	})
	if err != nil {
		log.Fatalf("failed to init client: %v", err)
	}

	// Verify an incoming Bearer token
	session, err := c.Sessions.VerifyToken(context.Background(), "user_token_here")
	if err != nil {
		log.Printf("invalid session: %v", err)
		return
	}

	fmt.Printf("Authenticated user ID: %s, Email: %s\n", session.UserID, session.Email)
}
```

## Chi HTTP Middleware Example

```go
func AuthSetuMiddleware(c *client.Client) func(http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			token := r.Header.Get("Authorization")
			if token == "" {
				http.Error(w, `{"error":"unauthorized"}`, http.StatusUnauthorized)
				return
			}

			sess, err := c.Sessions.VerifyToken(r.Context(), token)
			if err != nil {
				http.Error(w, `{"error":"invalid_token"}`, http.StatusUnauthorized)
				return
			}

			ctx := context.WithValue(r.Context(), "user_id", sess.UserID)
			next.ServeHTTP(w, r.WithContext(ctx))
		})
	}
}
```
