Skip to content
OpenShell
You are viewing Go SDK 0.1.7. The latest version is 0.1.8. Go to the latest version.

Client

Constructor: v1.NewClient(config)

Client is the root entry point for SDK operations. It provides typed accessors for each resource domain and manages the underlying gRPC connection. The ClientInterface covers the stable core accessors; additive helpers such as SandboxTemplates() are available on the concrete client.

Accessor Returns Description
Sandboxes() SandboxInterface Sandbox lifecycle management
SandboxTemplates() SandboxTemplateInterface Reusable sandbox template management
Providers() ProviderInterface Provider CRUD and idempotent ensure
Services() ServiceInterface Service exposure and management
Exec() ExecInterface Command execution (run, stream, interactive)
Files() FileInterface File upload and download
Health() HealthInterface Gateway health checking
SSH() SSHInterface SSH session and tunnel management
TCP() TCPInterface TCP port forwarding
Config() ConfigInterface Sandbox and gateway configuration
Policy() PolicyInterface Draft policy review workflow
Close() error Close the gRPC connection

Sub-client hierarchy: Providers() has two nested accessors:

  • client.Providers().Profiles() returns ProfileInterface
  • client.Providers().Refresh() returns RefreshInterface
import v1 "github.com/ai-openshell/sdk-go/openshell/v1"
client, err := v1.NewClient(v1.Config{
Address: "gateway.example.com:443",
Auth: v1.StaticToken("my-token"),
})
if err != nil {
log.Fatal(err)
}
defer client.Close()

The Config struct controls connection behavior:

type Config struct {
Address string // Gateway address (host:port)
TLS *TLSConfig // TLS settings (nil uses system defaults)
Auth AuthProvider // Authentication provider
Timeout time.Duration // Default timeout for all operations (0 = no timeout)
RetryPolicy *RetryPolicy // Retry configuration (nil = no automatic retries)
Logger Logger // Custom logger (nil = no logging)
}

Authentication providers:

  • v1.StaticToken(token) provides a fixed bearer token
  • v1.NoAuth() skips authentication (for local development)

For unit tests, use the fake client instead of a real connection:

import "github.com/ai-openshell/sdk-go/openshell/v1/fake"
client := fake.NewClient()
defer client.Close()

The fake client implements the full ClientInterface with in-memory stores. See Testing for details.

See also: Getting Started, Architecture

We are a Cloud Native Computing Foundation sandbox project.