Skip to main content
Official SDK
Go 1.21+
Context Support

Go SDK

Production-grade Go SDK with context support and concurrent safety.

Go Idiomatic

Follows Go best practices and conventions

Concurrent Safe

Safe for concurrent use with goroutines

Strong Typing

Full type safety with Go interfaces

Minimal Dependencies

Lightweight with minimal external deps

Installation

Install using go get

go get github.com/settler/settler-go

Quick Start

Get started in 5 minutes

package main

import (
	"fmt"
	"log"
	
	"github.com/settler/settler-go/settler"
)

func main() {
	// Initialize client
	client, err := settler.NewClient("sk_your_api_key")
	if err != nil {
		log.Fatal(err)
	}

	// Create a reconciliation job
	job, err := client.Jobs().Create(settler.CreateJobRequest{
		Name: "Shopify-Stripe Reconciliation",
		Source: settler.AdapterConfig{
			Adapter: "shopify",
			Config: map[string]interface{}{
				"api_key": "your_shopify_api_key",
				"shop":     "your-shop",
			},
		},
		Target: settler.AdapterConfig{
			Adapter: "stripe",
			Config: map[string]interface{}{
				"api_key": "sk_your_stripe_key",
			},
		},
		Rules: settler.MatchingRules{
			Matching: []settler.MatchingRule{
				{Field: "order_id", Type: "exact"},
				{Field: "amount", Type: "exact", Tolerance: 0.01},
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// Run the job
	execution, err := client.Jobs().Run(job.ID)
	if err != nil {
		log.Fatal(err)
	}

	// Get report
	report, err := client.Reports().Get(job.ID, "")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Matched: %d\n", report.Summary.Matched)
}

Examples

Common use cases and patterns

Error Handling

import (
	"github.com/settler/settler-go/settler"
	"github.com/settler/settler-go/errors"
)

job, err := client.Jobs().Create(req)
if err != nil {
	switch e := err.(type) {
	case *errors.ValidationError:
		fmt.Printf("Validation error: %s\n", e.Message)
		fmt.Printf("Field: %s\n", e.Field)
	case *errors.AuthError:
		fmt.Printf("Authentication failed: %s\n", e.Message)
	case *errors.RateLimitError:
		fmt.Printf("Rate limit exceeded. Retry after: %v\n", e.RetryAfter)
	case *errors.NetworkError:
		fmt.Printf("Network error: %s\n", e.Message)
	default:
		fmt.Printf("Error: %s\n", err)
	}
}

Context Support

import (
	"context"
	"time"
)

// Use context for timeouts and cancellation
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

job, err := client.Jobs().CreateWithContext(ctx, req)
if err != nil {
	if err == context.DeadlineExceeded {
		fmt.Println("Request timed out")
	}
}