---
title: Go SDK
description: Install and use the official Trigv Go SDK for APIs, workers, CLIs, Cloud Run, Lambda, and backend services.
---
# Go SDK

Use the official Trigv Go SDK to send push notifications from APIs, workers, CLIs, Cloud Run, Lambda, and other backend services.

## Install

```
go get github.com/trigv/trigv-go@v1.0.0
```

## Send a notification

```
package main

import (
		"context"
		"log"
		"os"

		"github.com/trigv/trigv-go"
)

func main() {
		client, err := trigv.NewClient(trigv.ClientConfig{
			APIKey: os.Getenv("TRIGV_API_KEY"),
		})
		if err != nil {
			log.Fatal(err)
		}

		_, err = client.SendEvent(context.Background(), trigv.SendEventRequest{
			Channel:     "general",
			Title:       "Worker finished",
			Description: "Invoice sync completed",
			Level:       trigv.LevelSuccess,
			EventType:   "worker.completed",
		})
		if err != nil {
			log.Fatal(err)
		}
}
```

## Event fields

| Field | Required | Description |
| --- | :---: | --- |
| `Channel` | Yes | Channel slug, such as `general`, `deploys`, or `payments`. |
| `Title` | Yes | Push notification title. |
| `Description` | No | Body text shown in the notification. |
| `ImageURL` | No | HTTPS image URL for screenshots, charts, camera snapshots, or previews. |
| `URL` | No | Destination URL opened from the notification. |
| `Level` | No | `trigv.LevelInfo`, `LevelSuccess`, `LevelWarning`, or `LevelError`. |
| `DeliveryUrgency` | No | `standard` or `time_sensitive`. Defaults to `standard`. |
| `EventType` | No | Free-form event label such as `deploy.completed` or `cron.failed`. |
| `IdempotencyKey` | No | Deduplication key for safe retries. |

## Safe retries with idempotency

```
result, err := client.SendEvent(ctx, trigv.SendEventRequest{
		Channel:        "deploys",
		Title:          "Production deploy complete",
		IdempotencyKey: "deploy-prod-42",
})
if err != nil {
		return err
}
if result.Duplicate {
		log.Println("already sent")
}
```

## Configuration

| Option | Default | Description |
| --- | --- | --- |
| `APIKey` | `TRIGV_API_KEY` | Workspace API key. |
| `BaseURL` | `https://api.trigv.com/api` | API base URL. |
| `Timeout` | `30` | Request timeout in seconds. |
| `MaxRetries` | `2` | Retry count for retryable failures; `0` disables retries. |

## Verify the API key

```
connection, err := client.VerifyConnection(ctx)
if err != nil {
		log.Fatal(err)
}
log.Println(connection.Workspace.Name)
```

## Error handling

```
result, err := client.SendEvent(ctx, req)
if err != nil {
		var validationErr *trigv.ValidationError
		var notFoundErr *trigv.NotFoundError
		var rateErr *trigv.RateLimitError

		switch {
		case errors.As(err, &validationErr):
			log.Println(validationErr.Errors)
		case errors.As(err, &notFoundErr):
			log.Println("channel not found")
		case errors.As(err, &rateErr):
			log.Println("retryable:", rateErr.Retryable)
		default:
			log.Println(err)
		}
}
```

## Good places to use it

- Go APIs and microservices
- Cloud Run, Lambda, Fly.io, Railway, and background workers
- CLI tools and scheduled jobs written in Go

<DocsResourceLinks
  packageHref="https://pkg.go.dev/github.com/trigv/trigv-go"
  packageTitle="Go package"
  packageDescription="View the official Trigv Go SDK on pkg.go.dev."
  packageLabel="Go"
  sourceHref="https://github.com/Trigv/trigv-go"
  sourceDescription="View the Go SDK source on GitHub."
/>
