Documentation
¶
Overview ¶
Package shared provides common utilities for all examples.
Index ¶
- func DecodeJSON(r *http.Request, v any) error
- func ErrorResponse(w http.ResponseWriter, status int, message string)
- func GetCacheDir() string
- func GetEnv(key, defaultValue string) string
- func GetEnvBool(key string, defaultValue bool) bool
- func GetEnvDuration(key string, defaultValue time.Duration) time.Duration
- func GetEnvInt(key string, defaultValue int) int
- func GetEnvInt64(key string, defaultValue int64) int64
- func JSONResponse(w http.ResponseWriter, status int, data any)
- func ReadFile(ctx context.Context, instance cc.Instance, path string) ([]byte, error)
- func WriteFiles(ctx context.Context, instance cc.Instance, files map[string][]byte) error
- type BaseConfig
- type Histogram
- type Metrics
- type RunResult
- func RunCommand(ctx context.Context, instance cc.Instance, name string, args ...string) RunResult
- func RunCommandWithEnv(ctx context.Context, instance cc.Instance, env []string, name string, ...) RunResult
- func RunCommandWithStdin(ctx context.Context, instance cc.Instance, stdin io.Reader, name string, ...) RunResult
- type SandboxPool
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes a JSON request body.
func ErrorResponse ¶
func ErrorResponse(w http.ResponseWriter, status int, message string)
ErrorResponse writes a JSON error response.
func GetCacheDir ¶
func GetCacheDir() string
GetCacheDir returns a directory for caching filesystem snapshots. Uses CC_CACHE_DIR env var, or falls back to user cache directory.
func GetEnvBool ¶
GetEnvBool returns an environment variable as bool or a default value.
func GetEnvDuration ¶
GetEnvDuration returns an environment variable as duration or a default value.
func GetEnvInt64 ¶
GetEnvInt64 returns an environment variable as int64 or a default value.
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, status int, data any)
JSONResponse writes a JSON response.
Types ¶
type BaseConfig ¶
type BaseConfig struct {
Port string
LogLevel string
DefaultMemoryMB uint64
DefaultTimeout time.Duration
MaxConcurrent int
}
BaseConfig contains common configuration options.
func LoadBaseConfig ¶
func LoadBaseConfig() BaseConfig
LoadBaseConfig loads base configuration from environment.
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
Histogram is a simple histogram implementation.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics collects Prometheus-compatible metrics.
func (*Metrics) Handler ¶
func (m *Metrics) Handler() http.HandlerFunc
Handler returns an HTTP handler for /metrics endpoint.
type RunResult ¶
type RunResult struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
Duration time.Duration `json:"duration_ms"`
TimedOut bool `json:"timed_out,omitempty"`
Error string `json:"error,omitempty"`
}
RunResult contains the result of running a command in a sandbox.
func RunCommand ¶
RunCommand runs a command in an instance and captures output.
type SandboxPool ¶
type SandboxPool struct {
// contains filtered or unexported fields
}
SandboxPool manages a pool of pre-warmed sandbox instances.
func NewSandboxPool ¶
func NewSandboxPool(source cc.InstanceSource, size int, opts ...cc.Option) *SandboxPool
NewSandboxPool creates a new sandbox pool.
func (*SandboxPool) Close ¶
func (p *SandboxPool) Close() error
Close closes all instances in the pool.
func (*SandboxPool) Release ¶
func (p *SandboxPool) Release(instance cc.Instance)
Release returns an instance to the pool or closes it.
type Server ¶
Server wraps http.Server with graceful shutdown and common middleware.
func (*Server) HealthHandler ¶
func (s *Server) HealthHandler() http.HandlerFunc
HealthHandler returns a health check handler.
func (*Server) ListenAndServeWithGracefulShutdown ¶
ListenAndServeWithGracefulShutdown starts the server and handles graceful shutdown.
func (*Server) ReadyHandler ¶
func (s *Server) ReadyHandler() http.HandlerFunc
ReadyHandler returns a readiness check handler.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package testrunner provides a YAML-driven test framework for example services.
|
Package testrunner provides a YAML-driven test framework for example services. |
|
cmd/runtest
command
Command runtest executes YAML-driven tests for example services.
|
Command runtest executes YAML-driven tests for example services. |