title: Go SDK

description: Install and use the official Wontopos Go SDK.

Go SDK

The official Go SDK with idiomatic patterns, full context support, and automatic retries. Requires Go 1.21+.

Installation

go get github.com/wontopos/wontopos-go

Initialize the client

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

client := wontopos.NewClient(os.Getenv("WONTOPOS_API_KEY"))

Configuration options

client := wontopos.NewClient(
    "wont_...",
    wontopos.WithBaseURL("https://api.wontopos.com"),
    wontopos.WithTimeout(30 * time.Second),
    wontopos.WithMaxRetries(3),
)

Basic usage

List marketplace APIs

resp, err := client.Marketplace.List(ctx, wontopos.MarketplaceListParams{
    Category: wontopos.String("payments"),
    Limit:    wontopos.Int(20),
})
if err != nil {
    log.Fatal(err)
}

for _, api := range resp.Data {
    fmt.Println(api.Name)
}

Create a subscription

sub, err := client.Subscriptions.Create(ctx, wontopos.SubscriptionCreateParams{
    APIID:  "api_abc123",
    PlanID: "plan_pro",
})

Context handling

All methods accept a context.Context as the first argument for cancellation and timeouts:

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

apis, err := client.Marketplace.List(ctx, wontopos.MarketplaceListParams{})

Request cancellation

Pass a cancellable context to abort long-running requests. The SDK respects context deadlines for all HTTP calls.

Auto-pagination

iter := client.Marketplace.ListAutoPaging(ctx, wontopos.MarketplaceListParams{
    Category: wontopos.String("payments"),
})
for iter.Next() {
    api := iter.Current()
    fmt.Println(api.Name)
}
if err := iter.Err(); err != nil {
    log.Fatal(err)
}

Error handling

import "github.com/wontopos/wontopos-go/errors"

resp, err := client.Marketplace.Get(ctx, "api_invalid")
if err != nil {
    var apiErr *wontopos.APIError
    if stderrors.As(err, &apiErr) {
        fmt.Println("Code:", apiErr.Code, "Status:", apiErr.Status)
    }
    var rateLimitErr *errors.RateLimitError
    if stderrors.As(err, &rateLimitErr) {
        fmt.Println("Retry after:", rateLimitErr.RetryAfter)
    }
}