Skip to main content

Go SDK

The flare-go module is published on pkg.go.dev and follows the same wire contract as every other Flare SDK. Zero third-party dependencies — uses net/http, encoding/json, and crypto/hmac from the standard library.

go get github.com/zeridion/flare-go

Requires: Go 1.22+

Quick start

package main

import (
"context"
"fmt"
"log"

flare "github.com/zeridion/flare-go"
)

func main() {
client, err := flare.NewClient(flare.WithAPIKey("zf_live_sk_..."))
if err != nil {
log.Fatal(err)
}

job, err := client.CreateJob(context.Background(), &flare.CreateJobRequest{
JobType: "SendWelcomeEmail",
Payload: map[string]any{"email": "alice@example.com"},
Queue: "default",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(job.ID, job.State) // "job_abc123 pending"
}

Or, with FLARE_API_KEY set in the environment, omit flare.WithAPIKey(...).

Client construction

client, err := flare.NewClient(
flare.WithAPIKey("zf_live_sk_..."),
flare.WithBaseURL("https://api.zeridion.com"), // override for dev / staging
flare.WithMaxRetries(3), // 0 to disable retries
flare.WithRetryBaseDelay(500 * time.Millisecond),
flare.WithRetryMaxDelay(30 * time.Second),
flare.WithTimeout(30 * time.Second),
flare.WithMaxResponseBytes(10 * 1024 * 1024), // 10 MiB cap (0 disables)
)

The default per-request timeout is 30 seconds. Override it via flare.WithTimeout(...); the value is applied to every outbound HTTP request the client makes.

Typed error hierarchy

The following are exported from the flare package:

TypeHTTPWhen it fires
flare.ErrorBase type for every SDK error
flare.AuthError401Missing / invalid / revoked API key
flare.QuotaError402Daily quota exceeded
flare.NotFoundError404Resource doesn't exist
flare.ConflictError409Idempotency or invalid-state conflict
flare.RateLimitError429Inspect .RetryAfter, .Limit, .Remaining

Use the package's As* helpers to unwrap into a typed pointer, or fall back to errors.As from the standard library:

// Idiomatic — package-supplied helper:
if rle, ok := flare.AsRateLimitError(err); ok {
log.Printf("rate limited, retry after %d (epoch sec)", rle.RetryAfter)
return
}

// Equivalent stdlib form:
var rle *flare.RateLimitError
if errors.As(err, &rle) {
log.Printf("rate limited, retry after %d (epoch sec)", rle.RetryAfter)
return
}

The same pattern works for AsAuthError, AsQuotaError, AsNotFoundError, and AsConflictError.

Method reference

client.CreateJob(ctx, req, opts...) // POST /flare/v1/jobs
client.GetJob(ctx, id, opts...) // GET /flare/v1/jobs/{id} — returns (nil, nil) for 404
client.ListJobs(ctx, lo, opts...) // GET /flare/v1/jobs (cursor-paginated)
client.CancelJob(ctx, id, opts...) // POST /flare/v1/jobs/{id}/cancel — returns (nil, nil) for 409
client.RetryJob(ctx, id, opts...) // POST /flare/v1/jobs/{id}/retry — returns (nil, nil) for 409
client.PollWorkers(ctx, req, opts...) // POST /flare/v1/workers/poll
client.AckWorker(ctx, req, opts...) // POST /flare/v1/workers/ack

PollWorker (singular) is kept as a deprecated alias for PollWorkers and will be removed at v1.0.

Feature parity

See the SDK overview for the full feature-parity matrix across .NET, TypeScript, Python, Go, Java, PHP, and Ruby.

Source

github.com/zeridion/flare-go

See also

  • Java SDK — JVM equivalent with the same REST surface
  • Jobs API — wire-level reference for the endpoints this SDK wraps
  • Errors — status codes and error envelopes used by every SDK