Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vers Go API Library

This library provides convenient access to the Vers REST API from Go.

It is generated with Sterling.

Installation

go get github.com/hdresearch/go-sdk

Usage

package main

import (
	"fmt"
	vers "github.com/hdresearch/go-sdk"
)

func main() {
	client := vers.NewClient(
		"https://api.vers.sh",
		"your-api-key", // or set VERS_API_KEY env var
	)

	// List all VMs
	resp, err := client.ListVms()
	if err != nil {
		panic(err)
	}
	fmt.Println(resp.StatusCode)

	// Branch a VM
	resp, err = client.BranchVm("vm-id", nil, &vers.BranchVmParams{
		Count: intPtr(3),
	})
}

func intPtr(i int64) *int64 { return &i }

Configuration

client := vers.NewClient("https://api.vers.sh", "your-api-key",
	vers.WithHTTPClient(&http.Client{Timeout: 60 * time.Second}),
)
client.MaxRetries = 3
client.LogLevel = vers.LogInfo

Error handling

resp, err := client.DeleteVm("nonexistent-id", nil)
if err != nil {
	fmt.Println("connection error:", err)
}
if resp.StatusCode == 404 {
	fmt.Println("VM not found")
}

Retries

Requests are automatically retried up to 2 times on 5xx errors and connection failures, with exponential backoff and jitter. The client respects Retry-After headers (capped at 60s).

Requirements

  • Go 1.21+

License

MIT

About

Vers SDK — generated from the Vers OpenAPI spec

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages