Skip to main content

Go SDK

The official Go SDK for the Generator Labs API v4.0.

Packagegithub.com/generator-labs/go-sdk
Minimum versionGo 1.21+
DependenciesStandard library only
GitHubgenerator-labs/go-sdk

Installation​

go get github.com/generator-labs/go-sdk

Usage​

package main

import (
generatorlabs "github.com/generator-labs/go-sdk"
"fmt"
"log"
)

func main() {
client := generatorlabs.New("your_account_sid", "your_auth_token")

// Get a single host
host, err := client.RBL().Hosts().Get("host_id")
if err != nil {
log.Fatal(err)
}
fmt.Println(host)

// List all hosts with automatic pagination
hosts, err := client.RBL().Hosts().GetAll(nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(hosts)

// Create a certificate monitor
monitor, err := client.Cert().Monitors().Create(generatorlabs.CertMonitorParams{
Name: "example.com",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(monitor)
}

Configuration​

client := generatorlabs.New("your_account_sid", "your_auth_token",
&generatorlabs.Config{
Timeout: 45 * time.Second,
MaxRetries: 5,
RetryBackoff: 2.0,
},
)
OptionDefaultDescription
Timeout30sTotal request timeout
ConnectTimeout5sTCP connection timeout
MaxRetries3Maximum number of retry attempts
RetryBackoff1.0Backoff multiplier between retries
BaseURL:Override the default API base URL

Webhook Verification​

err := generatorlabs.VerifyWebhook(body, signatureHeader, secret, tolerance)
if err != nil {
log.Fatal("Invalid webhook signature")
}

See Using Web Hooks for more details on webhook payloads and signature verification.

Error Handling​

The Go SDK uses idiomatic error returns. All methods return the result and an error as the second value:

host, err := client.RBL().Hosts().Get("host_id")
if err != nil {
log.Fatal(err)
}

Rate Limit Information​

Rate limit details are available on every response:

fmt.Println(response.RateLimit.Remaining)
fmt.Println(response.RateLimit.Reset)

See What Are the API Rate Limits? for more information.