Integrations
Go
Use the SafeURL Go SDK
The Go SDK is generated from the OpenAPI spec and lives in its own repository at github.com/gnoverse/safeurl-sdk.
Installation
go get github.com/gnoverse/safeurl-sdk/goUsing from the SafeURL monorepo: In your Go project's go.mod:
replace github.com/gnoverse/safeurl-sdk/go => /path/to/safeurl-sdk/goQuick example
package main
import (
"context"
"fmt"
"log"
"os"
"time"
safeurl "github.com/gnoverse/safeurl-sdk/go"
)
func main() {
client, err := safeurl.NewClientWithAPIKey(safeurl.DefaultBaseURL, os.Getenv("SAFEURL_API_KEY"))
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Submit a scan
resp, err := client.PostV1ScansWithResponse(ctx, map[string]interface{}{
"url": "https://example.com",
})
if err != nil {
log.Fatal(err)
}
if resp.JSON201 == nil {
log.Fatal("Unexpected response status:", resp.StatusCode())
}
fmt.Println("Scan submitted successfully")
}Batch scan
batch, err := client.Scans.CreateBatch(ctx, safeurl.BatchScanRequest{
URLs: []string{
"https://example.com",
"https://suspicious-site.xyz",
},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Batch ID: %s, jobs: %d\n", batch.BatchID, len(batch.Jobs))Regenerating the SDK
The SDK is generated from the live OpenAPI spec. With the API running locally:
bun run codegen:go-sdk