Back to SDKsView on GitHub
Go SDK
Idiomatic Go SDK with context support, structured errors, and connection pooling.
go get github.com/coverkit/coverkit-goInstallation
go get github.com/coverkit/coverkit-goQuick Start
package main
import (
"context"
"fmt"
"log"
"github.com/coverkit/coverkit-go"
)
func main() {
// Initialize the client
client := coverkit.NewClient(
coverkit.WithAPIKey("sk_live_your_api_key"),
coverkit.WithEnvironment(coverkit.Production),
)
ctx := context.Background()
// Create a quote
quote, err := client.Quotes.Create(ctx, &coverkit.QuoteCreateParams{
Product: coverkit.ProductShippingProtection,
Coverage: &coverkit.Coverage{
ItemValue: 15000, // $150.00 in cents
ShippingMethod: "ground",
},
Customer: &coverkit.Customer{
Email: "customer@example.com",
},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Quote ID: %s\n", quote.ID)
fmt.Printf("Premium: $%.2f\n", float64(quote.Premium)/100)
// Bind the quote to create a policy
policy, err := client.Policies.Create(ctx, &coverkit.PolicyCreateParams{
QuoteID: quote.ID,
Payment: &coverkit.Payment{
Method: "stripe",
Token: "tok_visa",
},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Policy ID: %s\n", policy.ID)
fmt.Printf("Status: %s\n", policy.Status)
}Features
Idiomatic Go
Follows Go best practices and conventions.
Context Support
Full context.Context support for cancellation and timeouts.
Structured Errors
Rich error types with error codes and details.
Connection Pooling
Efficient HTTP connection reuse for high throughput.
Error Handling
quote, err := client.Quotes.Create(ctx, params)
if err != nil {
var apiErr *coverkit.Error
if errors.As(err, &apiErr) {
fmt.Printf("API Error: %s (code: %s)\n", apiErr.Message, apiErr.Code)
// Handle specific error codes
switch apiErr.Code {
case coverkit.ErrInvalidProduct:
// Handle invalid product
case coverkit.ErrRateLimited:
// Handle rate limit
}
}
return err
}