Skip to content

Go SDK

The github.com/sangho/sangho-go module is the official Sangho client for Go 1.21+. It is idiomatic, fully typed, and designed for production environments — with no unnecessary third-party dependencies.

Installation

bash
go get github.com/sangho/sangho-go

Available modules

AppsAddressesPaymentIntentsCheckoutSessionsTransactionsRefundsPaymentLinksCustomersPaymentMethodsProductsInvoicesReceiptsSubscriptionsWebhooksSecurityTerminal
Idiomatic Go

All API responses return a (result, error) tuple. Optional parameters are passed via dedicated structs suffixed with Params — e.g. PaymentIntentCreateParams. Zero empty interface{} in critical code paths.

Initialization

go
package main


import (
    "os"
    sangho "github.com/sangho/sangho-go"
)


func main() {
    // Direct key (not recommended in production)
    client := sangho.NewClient("sk_prod_xxxxxxxxxxxx")


    // From environment variable (recommended)
    client := sangho.NewClient(os.Getenv("SANGHO_SECRET_KEY"))


    // Advanced options
    client := sangho.NewClient(
        os.Getenv("SANGHO_SECRET_KEY"),
        sangho.WithBaseURL("https://api.sangho.ga/v1/"),
        sangho.WithTimeout(30*time.Second),
        sangho.WithMaxRetries(3),
    )
}

Error handling

Errors returned by the SDK are of type *sangho.Error. Use errors.As to access the business fields Code, Message, and HTTPStatus.

Pagination

List endpoints return a generic type sangho.ListResponse[T] with fields Count, Next, Previous, and Results. Use the Page and PageSize parameters to navigate.

Automatic retry

The SDK automatically retries 429 (rate limit) and 5xx errors with exponential backoff. Configure WithMaxRetries at initialization (default: 3).

Error handling

go
package main


import (
    "errors"
    "fmt"
    "os"
    sangho "github.com/sangho/sangho-go"
)


func main() {
    client := sangho.NewClient(os.Getenv("SANGHO_SECRET_KEY"))


    intent, err := client.PaymentIntents.Create(ctx,
        sangho.PaymentIntentCreateParams{
            Amount:             5000,
            Currency:           "XAF",
            PaymentMethodTypes: []string{"mobile_money"},
        },
    )
    if err != nil {
        var sErr *sangho.Error
        if errors.As(err, &sErr) {
            fmt.Println(sErr.Code)       // Sangho business code
            fmt.Println(sErr.Message)    // Human-readable message
            fmt.Println(sErr.HTTPStatus) // HTTP status code (400, 401, 422…)
        }
        return
    }
    fmt.Println(intent.ID)
}

Pagination

go
// Page 1
page1, err := client.Transactions.List(ctx,
    sangho.TransactionListParams{
        Status:   "completed",
        Page:     1,
        PageSize: 20,
    },
)
if err != nil { /* ... */ }


fmt.Println(page1.Count)   // Total results
fmt.Println(page1.Results) // Current page slice


// Next page
if page1.Next != "" {
    page2, err := client.Transactions.List(ctx,
        sangho.TransactionListParams{
            Status:   "completed",
            Page:     2,
            PageSize: 20,
        },
    )
    _ = page2
    _ = err
}