client

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the Go client for the Den API.

func New

func New(baseURL string, opts ...Option) *Client

New creates a new Den client.

func (*Client) CreateSandbox

func (c *Client) CreateSandbox(ctx context.Context, cfg SandboxConfig) (*Sandbox, error)

CreateSandbox creates a new sandbox.

func (*Client) CreateSnapshot

func (c *Client) CreateSnapshot(ctx context.Context, id string, name string) (*SnapshotInfo, error)

CreateSnapshot creates a snapshot of a sandbox.

func (*Client) DestroySandbox

func (c *Client) DestroySandbox(ctx context.Context, id string) error

DestroySandbox removes a sandbox.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, id string, opts ExecOpts) (*ExecResult, error)

Exec runs a command in a sandbox.

func (*Client) GetSandbox

func (c *Client) GetSandbox(ctx context.Context, id string) (*Sandbox, error)

GetSandbox returns a sandbox by ID.

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health checks server health.

func (*Client) ListSandboxes

func (c *Client) ListSandboxes(ctx context.Context) ([]Sandbox, error)

ListSandboxes returns all sandboxes.

func (*Client) ReadFile

func (c *Client) ReadFile(ctx context.Context, id string, path string) ([]byte, error)

ReadFile reads a file from a sandbox.

func (*Client) RestoreSnapshot

func (c *Client) RestoreSnapshot(ctx context.Context, snapshotID string) (*Sandbox, error)

RestoreSnapshot restores a sandbox from a snapshot.

func (*Client) StopSandbox

func (c *Client) StopSandbox(ctx context.Context, id string) error

StopSandbox stops a sandbox.

func (*Client) WriteFile

func (c *Client) WriteFile(ctx context.Context, id string, path string, content []byte) error

WriteFile writes a file to a sandbox.

type ExecOpts

type ExecOpts struct {
	Cmd     []string          `json:"cmd"`
	Env     map[string]string `json:"env,omitempty"`
	WorkDir string            `json:"workdir,omitempty"`
	Timeout int               `json:"timeout,omitempty"` // seconds
}

ExecOpts holds options for command execution.

type ExecResult

type ExecResult struct {
	ExitCode int    `json:"exit_code"`
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
}

ExecResult holds the result of command execution.

type Option

type Option func(*Client)

Option configures the Client.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key for authentication.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sets a custom HTTP client.

type PortMapping added in v0.0.3

type PortMapping struct {
	SandboxPort int    `json:"sandbox_port"`
	HostPort    int    `json:"host_port"`
	Protocol    string `json:"protocol,omitempty"`
}

PortMapping defines a port forwarding between host and sandbox.

type S3SyncConfig added in v0.0.3

type S3SyncConfig struct {
	Endpoint  string `json:"endpoint,omitempty"`
	Bucket    string `json:"bucket"`
	Prefix    string `json:"prefix,omitempty"`
	Region    string `json:"region,omitempty"`
	AccessKey string `json:"access_key,omitempty"`
	SecretKey string `json:"secret_key,omitempty"`
	Mode      string `json:"mode"`
	MountPath string `json:"mount_path,omitempty"`
	SyncPath  string `json:"sync_path,omitempty"`
}

S3SyncConfig holds S3 synchronization settings for a sandbox.

type Sandbox

type Sandbox struct {
	ID        string    `json:"id"`
	Image     string    `json:"image"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at,omitempty"`
}

Sandbox represents a sandbox instance.

type SandboxConfig

type SandboxConfig struct {
	Image    string            `json:"image,omitempty"`
	Env      map[string]string `json:"env,omitempty"`
	WorkDir  string            `json:"workdir,omitempty"`
	Timeout  int               `json:"timeout,omitempty"` // seconds
	CPU      int64             `json:"cpu,omitempty"`     // NanoCPUs (1e9 = 1 core)
	Memory   int64             `json:"memory,omitempty"`  // bytes
	PidLimit int64             `json:"pid_limit,omitempty"`
	Ports    []PortMapping     `json:"ports,omitempty"`
	Storage  *StorageConfig    `json:"storage,omitempty"`
}

SandboxConfig holds sandbox creation options.

type SnapshotInfo

type SnapshotInfo struct {
	ID        string    `json:"id"`
	SandboxID string    `json:"sandbox_id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

SnapshotInfo holds snapshot metadata.

type StorageConfig added in v0.0.3

type StorageConfig struct {
	Volumes []VolumeMount `json:"volumes,omitempty"`
	Tmpfs   []TmpfsMount  `json:"tmpfs,omitempty"`
	S3      *S3SyncConfig `json:"s3,omitempty"`
}

StorageConfig holds storage settings for a sandbox.

type TmpfsMount added in v0.0.3

type TmpfsMount struct {
	Path    string `json:"path"`
	Size    string `json:"size"`
	Options string `json:"options,omitempty"`
}

TmpfsMount defines a tmpfs filesystem to mount inside a sandbox.

type VolumeMount added in v0.0.3

type VolumeMount struct {
	Name      string `json:"name"`
	MountPath string `json:"mount_path"`
	ReadOnly  bool   `json:"read_only,omitempty"`
}

VolumeMount defines a named volume to mount into a sandbox.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL