s3origin

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package s3origin is cadish's S3-compatible upstream origin (e.g. AWS S3, OVH Object Storage, MinIO). Given an endpoint + bucket (+ static credentials), it fetches an object via the AWS SDK for Go v2's S3 GetObject, forwards the Range header for partial/seek requests (=> 206), and streams the response body so the server can tee it into the cache while serving the client.

It uses a shared, connection-pooling HTTP client so cadish can sustain heavy throughput without leaking sockets. CONNECTION-ESTABLISHMENT phases (dial, TLS, response headers) are bounded with timeouts so a black-holed or slow origin can't pin goroutines; the body transfer itself is NOT capped (large media) and relies on the per-request context for cancellation. See the origin package doc for the full streaming/ownership contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Endpoint is the S3-compatible endpoint URL (e.g.
	// "https://s3.gra.io.cloud.ovh.net"). Required.
	Endpoint string
	// Region is the S3 region (e.g. "gra"). Required by the SDK; for many
	// S3-compatible stores any non-empty value works.
	Region string
	// Bucket is the bucket to fetch from. Required.
	Bucket string
	// AccessKey / SecretKey are static credentials. Required for private buckets.
	// When BOTH are empty the origin fetches ANONYMOUSLY (see Anonymous) — signing a
	// request with empty static credentials is rejected by S3/MinIO, so empty creds
	// must mean "no signing", not "sign with an empty key".
	AccessKey string
	SecretKey string
	// Anonymous forces unsigned (public-bucket) requests. It is also implied when
	// AccessKey and SecretKey are both empty.
	Anonymous bool
	// UsePathStyle forces path-style addressing (/<bucket>/<key>) instead of
	// virtual-host style. Most S3-compatible stores (OVH, MinIO) need this true.
	UsePathStyle bool
}

Config configures an S3-compatible origin. It is a plain value type (no dependency on cadish's Cadishfile config package) so the origin layer stays self-contained.

type Option

type Option func(*s3.Options)

Option configures an Origin.

func WithHTTPClient

func WithHTTPClient(hc aws.HTTPClient) Option

WithHTTPClient overrides the S3 client's HTTP client (tests point this at an httptest server).

type Origin

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

Origin fetches objects from one S3 bucket.

func New

func New(cfg Config, opts ...Option) *Origin

New builds an S3-compatible origin from cfg. It wires a connection-pooling HTTP client with bounded establishment timeouts (body transfer uncapped). Additional raw s3.Options can be tweaked via opts (tests inject a custom HTTP client this way).

func (*Origin) Fetch

func (o *Origin) Fetch(ctx context.Context, in *origin.Request) (*origin.Response, error)

Fetch implements origin.Origin. It forwards the Range header (=> 206), streams the body (no buffering), maps NoSuchKey/404 to origin.ErrNotFound, and surfaces any other non-success status as a *origin.StatusError. The returned Response.Body MUST be closed by the caller. See the origin package doc.

Jump to

Keyboard shortcuts

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