Introduction to the Go SDK
Welcome to the Go SDK for interacting with the Our API. This SDK simplifies the process of making requests to our platform from your Go applications, providing a type-safe and idiomatic Go experience.
Why Use the Go SDK?
- Simplified Interaction: Abstract away the complexities of HTTP requests, authentication, and JSON parsing.
- Type Safety: Leverage Go's strong typing to catch errors at compile time, not runtime.
- Idiomatic Go: Designed with Go best practices in mind, ensuring it feels natural to use.
- Efficiency: Built for performance, just like Go itself.
Installation
To get started, you can install the SDK using Go Modules:
go get github.com/our-api/go-sdk
Getting Started: A Simple Example
Here’s a basic example demonstrating how to initialize the client and fetch a list of users:
Example: Fetching Users
package main
import (
"fmt"
"log"
"github.com/our-api/go-sdk"
)
func main() {
// Initialize the client with your API key
// Ensure you have your API_KEY set as an environment variable or replace it directly.
client, err := sdk.NewClient(sdk.WithAPIKey("YOUR_API_KEY"))
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Fetch a list of users
users, err := client.Users.List(sdk.UserListParams{})
if err != nil {
log.Fatalf("Failed to list users: %v", err)
}
fmt.Printf("Successfully fetched %d users:\n", len(users))
for _, user := range users {
fmt.Printf("- ID: %s, Name: %s, Email: %s\n", user.ID, user.Name, user.Email)
}
}
Note: Replace YOUR_API_KEY
with your actual API key. It's recommended to use environment variables for sensitive credentials.
Key Features
- Client Initialization: Easily configure the SDK with API keys, custom HTTP clients, or base URLs.
- Resource Clients: Dedicated clients for each API resource (e.g.,
Users
,Products
,Orders
) for organized access. - Request Parameters: Use struct-based parameters for clear and type-safe request configurations.
- Response Handling: Automatic deserialization of responses into Go structs and proper error propagation.
- HTTP Client Customization: Option to provide your own
http.Client
for advanced network configurations.
Next Steps
Now that you've got the basics, dive deeper into specific resources: