Flare has a Go SDK available on Github. It is a light wrapper around net/http.Client that automatically manages API authentication.

Installing

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.

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.

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

.

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

Paging Util Example
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(
		"/leaksdb/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 LeaksDB Sources, next=%s\n",
			fetchedPages,
			result.Next,
		)
	}

}