transport

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package transport wires the REST (oapi-codegen) and Connect-RPC clients used by the public e2b package. Everything here is internal: the exported helpers are thin constructors consumed by sandbox.go, volume/, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectCode

func ConnectCode(err error) connect.Code

ConnectCode extracts the Connect code if present; otherwise returns connect.CodeUnknown.

func IsConnectCode

func IsConnectCode(err error, code connect.Code) bool

IsConnectCode reports whether err is a Connect-RPC error with the given code.

func NewAPIClient

func NewAPIClient(baseURL string, hc *http.Client, auth Auth) (*apiclient.Client, error)

NewAPIClient builds the control-plane REST client (https://api.<domain>).

func NewVolumeAPIClient

func NewVolumeAPIClient(baseURL string, hc *http.Client, token string, extraHeaders map[string]string) (*volumeapi.Client, error)

NewVolumeAPIClient builds the volume-content REST client using a JWT bearer token scoped to a single volume.

Types

type Auth

type Auth struct {
	APIKey      string
	AccessToken string
	Headers     map[string]string
}

Auth describes how to authenticate against the control-plane REST API. Exactly one of APIKey or AccessToken should be set (APIKey wins if both).

func (Auth) AsRequestEditor

func (a Auth) AsRequestEditor() apiclient.RequestEditorFn

AsRequestEditor builds a RequestEditorFn that injects the auth header and any extra headers the caller supplied.

type EnvdAuth

type EnvdAuth struct {
	Token   string
	User    string
	Headers map[string]string
}

EnvdAuth is the envd (in-sandbox) access token. It is returned by the control plane when the sandbox is created. For Connect-RPC the token is carried as HTTP Basic auth with the token placed in the *username* slot. For plain HTTP endpoints (/files, /metrics, /envs) the token goes in an X-Access-Token header.

type EnvdClients

type EnvdClients struct {
	Process    processconnect.ProcessClient
	Filesystem filesystemconnect.FilesystemClient
	API        *envdapi.Client
}

NewEnvdClients builds the two Connect-RPC clients used by the sandbox (Process + Filesystem) plus the plain-HTTP client for /files, /metrics, /envs. baseURL is the envd root URL (https://49983-<id>.<domain>).

func NewEnvdClients

func NewEnvdClients(baseURL string, hc *http.Client, auth EnvdAuth) (*EnvdClients, error)

NewEnvdClients constructs Connect and REST clients for envd traffic.

type HTTPError

type HTTPError struct {
	Status  int
	Message string
	Body    []byte
}

HTTPError captures an unexpected HTTP response so the caller can classify it into the right SDK error type.

func ReadHTTPError

func ReadHTTPError(resp *http.Response) *HTTPError

ReadHTTPError parses an HTTP response body into an HTTPError. It does not close the body — the caller owns it.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Jump to

Keyboard shortcuts

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