Getting Started with the Go SDK

This guide will walk you through the essential steps to set up and start using our Go SDK to interact with our API. We'll cover installation, basic configuration, and your first API call.

Prerequisites

Step 1: Install the SDK

You can easily install the Go SDK using the standard Go modules command. Open your terminal and run:

go get github.com/our-company/our-api-go-sdk

Step 2: Initialize the SDK

In your Go project, you'll need to import the SDK and initialize it with your API credentials. Create a new Go file (e.g., main.go) and add the following code:

package main

import (
	"fmt"
	"log"

	"github.com/our-company/our-api-go-sdk/client"
)

func main() {
	// Replace "YOUR_API_KEY" with your actual API key
	apiKey := "YOUR_API_KEY"

	// Initialize the API client
	apiClient, err := client.NewClient(apiKey)
	if err != nil {
		log.Fatalf("Failed to create API client: %v", err)
	}

	fmt.Println("API client initialized successfully!")

	// Now you can use apiClient to make requests
	// For example:
	// resp, err := apiClient.SomeResource.List()
	// if err != nil {
	//     log.Fatalf("API request failed: %v", err)
	// }
	// fmt.Printf("API Response: %+v\n", resp)
}
Important: Never hardcode your API key directly in production code. Consider using environment variables or a secure secrets management system.

Step 3: Make Your First API Call

Once the client is initialized, you can start making calls to our API endpoints. Here's a simple example of how to fetch a list of resources:

package main

import (
	"fmt"
	"log"

	"github.com/our-company/our-api-go-sdk/client"
	// Import the specific resource package you want to use
	// e.g., "github.com/our-company/our-api-go-sdk/resources/items"
)

func main() {
	apiKey := "YOUR_API_KEY" // Remember to use a secure method for storing keys

	apiClient, err := client.NewClient(apiKey)
	if err != nil {
		log.Fatalf("Failed to create API client: %v", err)
	}

	fmt.Println("API client initialized successfully.")

	// Example: Fetching a list of items (replace with actual resource and method)
	// items, err := items.NewService(apiClient).List(context.Background(), &items.ListOptions{})
	// if err != nil {
	// 	log.Fatalf("Failed to fetch items: %v", err)
	// }
	//
	// fmt.Printf("Successfully fetched %d items.\n", len(items))
	// for _, item := range items {
	// 	fmt.Printf("- ID: %s, Name: %s\n", item.ID, item.Name)
	// }

	fmt.Println("Example call commented out. Uncomment and adapt for your use case.")
}

Remember to replace the commented-out example with the actual resource and method calls relevant to your needs. Refer to the API Reference for a complete list of available endpoints and their usage.

Next Steps

You've successfully set up the Go SDK! Now you can explore other functionalities: