Go SDK
The official Go SDK for the Generator Labs API v4.0.
| Package | github.com/generator-labs/go-sdk |
| Minimum version | Go 1.21+ |
| Dependencies | Standard library only |
| GitHub | generator-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,
},
)
| Option | Default | Description |
|---|---|---|
Timeout | 30s | Total request timeout |
ConnectTimeout | 5s | TCP connection timeout |
MaxRetries | 3 | Maximum number of retry attempts |
RetryBackoff | 1.0 | Backoff 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.