Go SDK
Generated Go client from the public OpenAPI spec — unwrap the response envelope in your app layer.
Loading article…
The Go module github.com/emailguard/emailguard-go is generated from openapi-public.yaml. Import it as emailguardsdk and call 20 team-scoped REST operations with typed request/response structs (version 1.0.0).
go get github.com/emailguard/emailguard-go/[email protected]Add the module to your go.mod and run go mod tidy after upgrading.
| Variable | Required | Description |
|---|---|---|
EMAILGUARD_API_KEY | Yes | Team-scoped live key (egsk_live_...) |
API_KEY is accepted as an alias in most clients.
Set the base URL via configuration if your deployment uses a custom API origin (https://api.emailguard.co by default in generated samples).
package main
import (
"context"
"fmt"
"os"
openapiclient "github.com/emailguard/emailguard-go/emailguardsdk"
)
func main() {
ctx := context.Background()
configuration := openapiclient.NewConfiguration()
configuration.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("EMAILGUARD_API_KEY"))
apiClient := openapiclient.NewAPIClient(configuration)
result, _, err := apiClient.TeamsAPI.ApiV1TeamGet(ctx).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "request failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("%+v\n", result)
}Generated methods return typed structs from the HTTP body. When the API responds with { "code", "data", "message" }, read the data field in your integration layer on success.
{
"code": "SUCCESS",
"data": { "..." : "..." },
"message": "OK"
}In practice, decode the JSON body and branch on code before using data in your handlers.
Each API reference page includes a Go SDK tab with imports and call syntax for that route.
cfg := emailguardsdk.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("EMAILGUARD_API_KEY"))
client := emailguardsdk.NewAPIClient(cfg)
// client.TeamsAPI.ApiV1TeamGet(ctx).Execute()Generated methods return (result, *http.Response, error). Inspect Response.StatusCode for 401, 403, and 429. See API rate limiting for quota headers and backoff.