---
title: Go
description: >-
  Impara a installare e usare l'SDK Go di Firmreader (Go 1.21 o superiore) per creare post, elencarli e gestire gli errori dell'API.
lastUpdated: "2026-08-17"
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

L'SDK Go richiede Go 1.21 o superiore. Ogni metodo accetta un `context.Context`, così puoi applicare timeout e annullamenti.

## Installazione

```bash
go get github.com/firmreader/firmreader-go
```

## Inizializzare il client

```go
package main

import (
	"os"

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

func main() {
	client := firmreader.NewClient(os.Getenv("FIRMREADER_API_KEY")) // fr_live_...
	_ = client
}
```

## Creare un post

```go
post, err := client.Posts.Create(ctx, &firmreader.PostParams{
	ChannelID: "ch_company_news",
	Title:     "Welcome to Firmreader",
	Body:      "We're excited to announce our new internal communications platform.",
	Priority:  "normal",
})
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Published post %s\n", post.ID)
```

## Elencare i post

```go
posts, err := client.Posts.List(ctx, &firmreader.ListParams{
	ChannelID: "ch_company_news",
	Limit:     20,
})
if err != nil {
	log.Fatal(err)
}

for _, post := range posts.Data {
	fmt.Println(post.Title)
}
```

## Gestire gli errori

Il client restituisce un `*firmreader.Error` per le risposte non 2xx. Usa `errors.As` per leggere lo stato e il codice.

```go
var apiErr *firmreader.Error
if errors.As(err, &apiErr) {
	fmt.Printf("%d: %s\n", apiErr.Status, apiErr.Code)
}
```

<Note>
Imposta `firmreader.WithIdempotencyKey("...")` su qualsiasi chiamata di scrittura, in modo che i nuovi tentativi non creino post duplicati.
</Note>
