Go Integration
Send transactional emails from Go applications with the Transactional SDK. Type-safe, efficient, and idiomatic Go.
Go SDK Features
The Transactional Go SDK is designed to be idiomatic and efficient:
- Context support for cancellation and timeouts
- Type-safe request and response structs
- Connection pooling via net/http
- Automatic retries for transient failures
- Zero dependencies beyond the standard library
Framework Integrations
The Go SDK works with any Go web framework:
- Gin - Popular HTTP framework
- Echo - High performance framework
- Fiber - Express-inspired framework
- Chi - Lightweight router
- net/http - Standard library
Error Handling
The SDK returns typed errors for easy handling:
result, err := client.Emails.Send(ctx, req)
if err != nil {
var apiErr *transactional.APIError
if errors.As(err, &apiErr) {
switch apiErr.Code {
case "INVALID_EMAIL":
// Handle invalid email
case "RATE_LIMITED":
// Back off and retry
case "QUOTA_EXCEEDED":
// Alert and stop
default:
// Log and retry
}
}
return err
}Configuration Options
client := transactional.NewClient(
os.Getenv("TRANSACTIONAL_API_KEY"),
transactional.WithTimeout(30*time.Second),
transactional.WithRetries(3),
transactional.WithBaseURL("https://api.transactional.dev"),
)Testing
Use the sandbox mode for testing:
func TestSendEmail(t *testing.T) {
client := transactional.NewClient(
os.Getenv("TRANSACTIONAL_API_KEY"),
transactional.WithSandbox(true),
)
result, err := client.Emails.Send(context.Background(), &transactional.SendEmailRequest{
From: "test@yourdomain.com",
To: []string{"test@example.com"},
Subject: "Test",
Text: "Test email",
})
assert.NoError(t, err)
assert.NotEmpty(t, result.ID)
assert.Equal(t, "sandbox", result.Status)
}