Skip to content

unikraft-cloud/go-sdk

Repository files navigation

Unikraft Cloud Go SDK

This repository contains an auto-generated Go SDK which interfaces with Unikraft Cloud based on the public OpenAPI specification.

Get started with Unikraft Cloud today!

Sign up at https://console.unikraft.cloud/signup.

Quickstart

package main

import (
	"context"
	"fmt"
	"os"

	"unikraft.com/cloud/sdk/platform"
)

func main() {
	ctx := context.Background()

	// Create a new client. The token and default metro are automatically
	// read from environment variables (UKC_TOKEN and UKC_METRO).
	client := platform.NewClient()

	// List all instances
	resp, err := client.GetInstances(ctx, nil, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
		os.Exit(1)
	}

	// Check for API-level errors
	if resp.Status != "success" {
		fmt.Fprintf(os.Stderr, "error: %s\n", resp.Message)
		os.Exit(1)
	}

	for _, inst := range resp.Data.Instances {
		fmt.Printf("Name:  %s\n", *inst.Name)
		fmt.Printf("UUID:  %s\n", *inst.Uuid)
		fmt.Printf("State: %s\n", *inst.State)
		fmt.Printf("Image: %s\n", *inst.Image)
		fmt.Println("---")
	}
}

See the examples/platform-list for a complete example.

Configuration

The SDK automatically reads configuration from environment variables:

  • UKC_TOKEN - Your Unikraft Cloud API token
  • UKC_METRO - The default metro/region to use (e.g., fra/sfo/dal/etc)

You can also configure the client programmatically using options:

client := platform.NewClient(
	platform.WithToken("your-api-token"),
	platform.WithDefaultMetro("fra"),
)

Options passed to NewClient() will override environment variables.

About

🔵 Unikraft Cloud Go SDK

Resources

License

Stars

Watchers

Forks

Contributors