thde.io/fairgate

GitHub · pkg.go.dev

fairgate

Go Reference test Go Report Card

This Go package wraps the Fairgate Standard API with a small, battery-included Go client.

Features

Installation

go get thde.io/fairgate

Getting Started

Import the module and construct a client with your organisation ID and Fairgate-issued ECDSA public key. The client defaults to the production endpoint; call WithTest() to target the sandbox.

Creating a client

package main

import (
	"context"
	"log"

	"github.com/golang-jwt/jwt/v5"
	"thde.io/fairgate"
)

func main() {
	key, err := jwt.ParseECPublicKeyFromPEM([]byte("PEM"))
	if err != nil {
		log.Fatalf("error parsing key: %v", err)
	}

	client := fairgate.New(
		"your-org-id",
		key,
		fairgate.WithUserAgent("my-app/1.0"),
	)
	if err = client.TokenCreate(context.TODO(), "access-key"); err != nil {
		log.Fatalf("error creating token: %v", err)
	}
}

Managing tokens

Call TokenCreate(ctx, accessKey) yourself before invoking other endpoints. The client validates expiry, refreshes when needed, and surfaces ErrNoAccessKey, ErrNoRefreshToken, or ErrStatus for troubleshooting. Provide WithAccessKey if you want the client to lazily call TokenCreate.

Streaming contacts with iterators

ContactsIter returns an iter.Seq2 that walks through all pages while respecting pagination metadata:

for contact, err := range client.ContactsIter(ctx) {
	if err != nil {
		log.Fatalf("iteration error: %v", err)
	}
	log.Println(contact)
}

Error Handling and Retries

Testing

Run them with the standard toolchain:

go test ./...

License

This project is distributed under the MIT License. See LICENSE for details.