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

# Go SDK

Flare has a Go SDK available on Github. It is a light wrapper around
[net/http.Client](https://pkg.go.dev/net/http#Client)
that automatically manages API authentication.

## Links

* [Github Repository](https://github.com/Flared/go-flareio)
* [Go Reference](https://pkg.go.dev/github.com/Flared/go-flareio)

## Installing

```bash theme={null}
go get github.com/Flared/go-flareio
```

## Basic Usage

The `flareio` package provides the `NewApiClient` method that can be used
to create a Flare API client.

The client exposes `Get` and `Post` methods that have a similar API to `net/http.Client`
with the exception that they accept paths as parameters instead of full URLs.

```go theme={null}
package main

import (
	"fmt"
	"io"
	"os"

	"github.com/Flared/go-flareio"
)

func main() {
	client := flareio.NewApiClient(
		os.Getenv("FLARE_API_KEY"),
	)
	resp, err := client.Get(
		"/tokens/test", nil,
	)
	if err != nil {
		fmt.Printf("failed to test token: %s\n", err)
		os.Exit(1)
	}
	defer resp.Body.Close()
	if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
		fmt.Printf("failed to print response: %s\n", err)
		os.Exit(1)
	}
}
```

## Specifying a Tenant Id

The Api Client can be configured to use a specific tenant id using the `WithTenantId` option.

```go theme={null}
client := flareio.NewApiClient(
    os.Getenv("FLARE_API_KEY"),
    flareio.WithTenantId(42),
)
// ...
```

## Paging Util

The `ApiClient` has `IterGet` and `IterPostJson` methods that return iterators implementing the
[Flare standard paging pattern <Icon icon="book" size={16} />](/concepts/paging).

<Note>
  The paging util leverages Go iterators which require Go version >= 1.23.
</Note>

```go Paging Util Example theme={null}
package main

import (
	"fmt"
	"os"
	"time"

	"github.com/Flared/go-flareio"
)

func main() {
	client := flareio.NewApiClient(
		os.Getenv("FLARE_API_KEY"),
	)

	fetchedPages := 0

	for result, err := range client.IterGet(
		"/astp/v2/sources", nil,
	) {
		// Rate Limiting
		time.Sleep(time.Second * 1)

		if err != nil {
			fmt.Printf("unexpected error: %s\n", err)
			os.Exit(1)
		}

		// Handle the response...
		result.Response.Body.Close()

		// Print the status
		fetchedPages = fetchedPages + 1
		fmt.Printf(
			"Fetched %d page(s) of ASTP Sources, next=%s\n",
			fetchedPages,
			result.Next,
		)
	}

}
```
