api

package
v0.11.1 Latest Latest
Warning

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

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

Documentation

Overview

Package api provides the Docker-compatible HTTP API server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSelfSignedCert

func GenerateSelfSignedCert(certFile, keyFile string) error

GenerateSelfSignedCert generates a self-signed certificate for testing. AE10: Generates self-signed certs when no cert is provided.

func GracefulShutdown

func GracefulShutdown(ctx context.Context, server *http.Server, timeout time.Duration)

GracefulShutdown handles OS signals for graceful shutdown.

func HealthHandler

func HealthHandler(w http.ResponseWriter, _ *http.Request)

AG8: HealthHandler returns comprehensive daemon health status.

func HealthHandlerV2

func HealthHandlerV2(w http.ResponseWriter, _ *http.Request)

HealthHandlerV2 returns comprehensive health status.

func MetricsHandler

func MetricsHandler(w http.ResponseWriter, _ *http.Request)

MetricsHandler serves Prometheus-compatible metrics.

func MetricsHandlerV2

func MetricsHandlerV2(w http.ResponseWriter, _ *http.Request)

MetricsHandler serves Prometheus-compatible metrics.

func NewTLSConfig

func NewTLSConfig(cfg *TLSConfig) (*tls.Config, error)

NewTLSConfig creates a tls.Config from the given settings.

func PprofHandler

func PprofHandler(w http.ResponseWriter, _ *http.Request)

PprofHandler returns a pprof index page for debugging.

func RecordError

func RecordError()

RecordError increments the error counter.

func RecordRequest

func RecordRequest()

RecordRequest increments the request counter.

func SetLogger

func SetLogger(l *slog.Logger)

SetLogger replaces the API package's logger. Subsequent log lines emitted by Middleware and handlers go through slog.

func TLSListener

func TLSListener(l net.Listener, tlsCfg *tls.Config) net.Listener

TLSListener wraps a regular listener with TLS.

func WaitForSignal

func WaitForSignal(cancel context.CancelFunc)

WaitForSignal blocks until SIGINT, SIGTERM, or SIGHUP is received, then calls the cancel function. Used by main to bridge os/signal to a context cancel.

func WithLogger

func WithLogger(ctx context.Context, l *slog.Logger) context.Context

WithLogger attaches a per-request logger.

func WithRequestID added in v0.11.1

func WithRequestID(ctx context.Context, rid string) context.Context

WithRequestID attaches a request ID to the request context.

Types

type MetricsCollector

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

MetricsCollector collects and exposes Prometheus-compatible metrics.

func NewMetricsCollector

func NewMetricsCollector() *MetricsCollector

NewMetricsCollector creates a new metrics collector.

func (*MetricsCollector) RecordContainerCreated

func (m *MetricsCollector) RecordContainerCreated()

RecordContainerCreated records a container creation.

func (*MetricsCollector) RecordContainerKilled

func (m *MetricsCollector) RecordContainerKilled()

RecordContainerKilled records a container kill.

func (*MetricsCollector) RecordContainerStarted

func (m *MetricsCollector) RecordContainerStarted()

RecordContainerStarted records a container start.

func (*MetricsCollector) RecordContainerStopped

func (m *MetricsCollector) RecordContainerStopped()

RecordContainerStopped records a container stop.

func (*MetricsCollector) RecordError

func (m *MetricsCollector) RecordError()

RecordError records an HTTP error.

func (*MetricsCollector) RecordExec

func (m *MetricsCollector) RecordExec()

RecordExec records an exec call.

func (*MetricsCollector) RecordImageBuilt

func (m *MetricsCollector) RecordImageBuilt()

RecordImageBuilt records an image build.

func (*MetricsCollector) RecordImagePulled

func (m *MetricsCollector) RecordImagePulled()

RecordImagePulled records an image pull.

func (*MetricsCollector) RecordNetworkCreated

func (m *MetricsCollector) RecordNetworkCreated()

RecordNetworkCreated records a network creation.

func (*MetricsCollector) RecordRequest

func (m *MetricsCollector) RecordRequest(duration time.Duration)

RecordRequest records an HTTP request.

func (*MetricsCollector) RecordVolumeCreated

func (m *MetricsCollector) RecordVolumeCreated()

RecordVolumeCreated records a volume creation.

func (*MetricsCollector) SetContainersPaused

func (m *MetricsCollector) SetContainersPaused(n int64)

SetContainersPaused sets the number of paused containers.

func (*MetricsCollector) SetContainersRunning

func (m *MetricsCollector) SetContainersRunning(n int64)

SetContainersRunning sets the number of running containers.

func (*MetricsCollector) SetImagesCount

func (m *MetricsCollector) SetImagesCount(n int64)

SetImagesCount sets the number of images.

func (*MetricsCollector) Snapshot

func (m *MetricsCollector) Snapshot() MetricsSnapshot

Snapshot returns a point-in-time snapshot of all metrics.

type MetricsSnapshot

type MetricsSnapshot struct {
	RequestsTotal     uint64  `json:"requests_total"`
	RequestsErrors    uint64  `json:"requests_errors"`
	ContainersCreated uint64  `json:"containers_created"`
	ContainersStarted uint64  `json:"containers_started"`
	ContainersStopped uint64  `json:"containers_stopped"`
	ContainersKilled  uint64  `json:"containers_killed"`
	ContainersRunning int64   `json:"containers_running"`
	ContainersPaused  int64   `json:"containers_paused"`
	ImagesPulled      uint64  `json:"images_pulled"`
	ImagesBuilt       uint64  `json:"images_built"`
	ImagesCount       int64   `json:"images_count"`
	NetworksCreated   uint64  `json:"networks_created"`
	VolumesCreated    uint64  `json:"volumes_created"`
	ExecCalls         uint64  `json:"exec_calls"`
	Goroutines        int     `json:"goroutines"`
	UptimeSeconds     float64 `json:"uptime_seconds"`
	AllocBytes        uint64  `json:"alloc_bytes"`
	SysBytes          uint64  `json:"sys_bytes"`
	NumGC             uint32  `json:"num_gc"`
	AvgRequestMs      float64 `json:"avg_request_ms"`
}

MetricsSnapshot is a point-in-time snapshot of metrics.

type Middleware

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

Middleware provides HTTP middleware for the API server.

func NewMiddleware

func NewMiddleware() *Middleware

NewMiddleware creates a new middleware chain.

func (*Middleware) CORS

func (m *Middleware) CORS(next http.Handler) http.Handler

CORS adds CORS headers.

func (*Middleware) Logging

func (m *Middleware) Logging(next http.Handler) http.Handler

Logging logs each request.

func (*Middleware) Recovery

func (m *Middleware) Recovery(next http.Handler) http.Handler

Recovery catches panics and returns 500.

func (*Middleware) RequestID

func (m *Middleware) RequestID(next http.Handler) http.Handler

RequestID adds a unique request ID header.

type RateLimit

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

RateLimit implements simple token bucket rate limiting.

func NewRateLimit

func NewRateLimit(requestsPerSec float64, burst int) *RateLimit

NewRateLimit creates a rate limiter.

func (*RateLimit) Allow

func (rl *RateLimit) Allow() bool

Allow checks if a request is allowed.

func (*RateLimit) RateLimitMiddleware

func (rl *RateLimit) RateLimitMiddleware(next http.Handler) http.Handler

RateLimitMiddleware applies rate limiting.

func (*RateLimit) Stop

func (rl *RateLimit) Stop()

type Server

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

Server implements the Docker Engine v1.44 compatible HTTP API.

func NewServer

func NewServer(config *common.DokiConfig, rt *dokiruntime.Runtime, img *image.Store, net *network.Manager) (*Server, error)

NewServer creates a new API server.

func (*Server) Listen

func (s *Server) Listen() error

Listen starts the API server.

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(path string, handler http.Handler)

RegisterHandler registers a custom handler for a path.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the configured middleware chain and router.

func (*Server) SetMiddleware

func (s *Server) SetMiddleware(middlewares ...func(http.Handler) http.Handler)

SetMiddleware configures middleware wrappers for the server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops the API server.

func (*Server) SocketPath

func (s *Server) SocketPath() string

SocketPath returns the API socket path.

type TLSConfig

type TLSConfig struct {
	Enabled  bool
	CertFile string
	KeyFile  string
	CAFile   string
	Verify   bool
	MinTLS   uint16
}

func DefaultTLSConfig

func DefaultTLSConfig() *TLSConfig

DefaultTLSConfig returns a default TLS configuration.

type VolumeManager

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

VolumeManager manages Docker-compatible volumes.

func NewVolumeManager

func NewVolumeManager(root string) (*VolumeManager, error)

NewVolumeManager creates a new volume manager.

func (*VolumeManager) Create

func (vm *VolumeManager) Create(name string, driver string, opts map[string]string, labels map[string]string) (*common.VolumeInfo, error)

func (*VolumeManager) Get

func (vm *VolumeManager) Get(name string) (*common.VolumeInfo, error)

func (*VolumeManager) List

func (vm *VolumeManager) List() []*common.VolumeInfo

func (*VolumeManager) Prune

func (vm *VolumeManager) Prune(referencedVolumes map[string]bool) ([]string, error)

func (*VolumeManager) Remove

func (vm *VolumeManager) Remove(name string) error

Jump to

Keyboard shortcuts

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