storage

package module
v0.0.0-...-c5ec8ae Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 67 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Storage

Object storage on S3 and S3-compatible stores, GCS, Azure Blob, OCI Object Storage, AliOSS and a local directory, behind one interface. storage.New(conf) returns a Storage; every call takes a context.

  • Bucket (storage/objects): PutObject, UploadObject (streams), GetObject, GetObjectRange, DownloadObject (to any io.Writer), ObjectExists, ListObjects (byte order), DeleteObjects, PresignedURL.
  • Storage is Bucket plus UploadFile and DownloadFile. DownloadFile replaces the local file only once the whole object is read.
  • PutOptions{ContentType, IfAbsent} on every write. IfAbsent refuses to replace an object, atomically where the store honors the condition.
  • Errors: a missing object is ErrNotFound, a write IfAbsent refuses is ErrExists (errors.Is); ErrorWithStatusCode carries the store's HTTP status and its error code, such as AccessDenied, and DeleteError the paths a delete left (errors.As).
  • storage/objects holds the interfaces in a module of its own, with no requirements (see Modules).

Behavior

  • S3 semantics where stores differ. DeleteObjects of a missing path succeeds, as S3's delete does. It tries every path, and when some are not deleted fails with a *DeleteError whose Failed names each one with its error (errors.As); every other path is deleted, and a retry is safe.
  • Keys are the store's keys as given. The local directory, as a filesystem, drops a leading /, cleans // and ., refuses keys outside it, and cannot hold both a and a/b.
  • Timeouts: a connection that moves no bytes either way for 5 minutes is cut. An HTTP/2 connection with no inbound frame for 30 seconds is pinged and cut when the ping goes unanswered for 15 seconds, so a dead peer fails every request on it within 45 seconds with an error the SDKs retry. The ping waits behind the frame being written, so a peer accepting less than one 16 KiB frame per 15 seconds is cut as well; any faster transfer, however slow, never is. The context bounds the call.
  • Retries: every store retries throttling, 5xx and network errors with backoff, including AliOSS, whose SDK does not. GCS also retries the errors with which Go's HTTP/2 client ends every request on a connection it is closing (force closed, or the server's GOAWAY), which the SDK does not. OCI also retries a request whose connection the server closed before answering, which the SDK does not, and a workload identity token fetch that fails, which the SDK makes once. It adds these to the retry policy the SDK is configured with (OCI_SDK_DEFAULT_RETRY_ENABLED, common.GlobalRetry), whose attempts and backoff stay. PresignedURL on OCI is sent again only when the server answered: a request with no answer may have made its grant. A stream given to UploadObject is sent once on AliOSS.
  • OCI setup: NewOCI makes no request. With workload identity the first call builds the client, which fetches its token, and a namespace the config leaves out is looked up by the first call too. Calls waiting on that share one attempt. A failure there fails those calls, each bounded by its context, and a later call tries again.
  • Proxy: ProxyConfig (S3, GCS) carries its credentials for http and https targets, honors NO_PROXY, and never proxies the cloud metadata services.
  • Local writes go in place, as a file is written, so mounted volumes and file watchers see one write; IfAbsent writes a temporary file (.upload-*, never listed) and links it into place.

Modules

module holds requires
github.com/livekit/storage the backends, New, the configs every provider SDK, livekit/protocol
github.com/livekit/storage/objects Bucket, Storage, PutOptions, the errors nothing
github.com/livekit/storage/e2e the end-to-end suites dockertest

Why objects is its own module:

  • A module's requirements take part in the version selection of every module that requires it, whichever packages it imports. In the root module, the interfaces would carry every SDK's and livekit/protocol's versions (grpc, otel) into each fake or library that implements or accepts them.
  • With no requirements, implementing them costs no dependency: gosim's fakes/objstore Bucket is an objects.Bucket.

How its versions work:

  • go.mod names the objects version the root requires; go.work builds the repo against objects/ in the tree.
  • A PR that changes objects/ under a released version gets the next minor version committed to it by objects-version.yaml, which also runs the checks on that commit; the PR's own runs for it wait for an approval nobody needs to give. Pull that commit before pushing again. From a fork, CI fails and prints the command.
  • Until the version is tagged, go mod tidy in the root fails on it (unknown revision); go.work builds the repo meanwhile.
  • On merge, objects-release.yaml tags objects/vX.Y.Z on main; a failed run can be rerun by hand. Squash merges drop a branch's commits, so only a version tagged on main is sure to stay resolvable.
  • test must be a required check on main with branches up to date: two PRs bumped to the same version cannot both merge then.

Tests

The suites live in the e2e module, so this module's users do not inherit Docker's dependencies.

  • go test ./... here runs the unit tests.
  • cd e2e && go test ./... runs every backend except AliOSS end to end: against floci emulators in Docker (S3, Azure Blob, GCS, OCI Object Storage), against MinIO for S3's conditional writes (MINIO_BIN or minio on PATH), and on the local directory. Without Docker or MinIO those tests skip, except when CI is set.
  • The provider tests (TestS3, TestGCP, ...) reach real accounts when their environment variables are set; AliOSS has no emulator and is covered only that way.

Documentation

Overview

Package storage is object storage on S3 and S3-compatible stores, GCS, Azure Blob, OCI Object Storage, AliOSS and a local directory, behind the interfaces in storage/objects. New builds a Storage from a config.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = objects.ErrNotFound
	ErrExists   = objects.ErrExists
)

Functions

This section is empty.

Types

type AliOSSConfig

type AliOSSConfig = config.AliOSSConfig

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type AzureConfig

type AzureConfig = config.AzureConfig

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type Bucket

type Bucket = objects.Bucket

The interfaces live in storage/objects so that code implementing or accepting them without creating one doesn't pull in every provider SDK.

type Config

type Config = config.Config

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type DeleteError

type DeleteError = objects.DeleteError

The interfaces live in storage/objects so that code implementing or accepting them without creating one doesn't pull in every provider SDK.

type ErrorWithStatusCode

type ErrorWithStatusCode = objects.ErrorWithStatusCode

The interfaces live in storage/objects so that code implementing or accepting them without creating one doesn't pull in every provider SDK.

type GCPConfig

type GCPConfig = config.GCPConfig

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type LocalConfig

type LocalConfig = config.LocalConfig

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type OCIConfig

type OCIConfig = config.OCIConfig

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type ProxyConfig

type ProxyConfig = config.ProxyConfig

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type PutOptions

type PutOptions = objects.PutOptions

The interfaces live in storage/objects so that code implementing or accepting them without creating one doesn't pull in every provider SDK.

type S3Config

type S3Config = config.S3Config

The config structs live in the storage/config package so that consumers which only embed them in their own config (and never create a Storage) don't pull in every provider SDK. These aliases keep the existing API.

type Storage

type Storage = objects.Storage

The interfaces live in storage/objects so that code implementing or accepting them without creating one doesn't pull in every provider SDK.

func New

func New(conf Config) (Storage, error)

New builds the Storage a config describes.

func NewAliOSS

func NewAliOSS(conf *AliOSSConfig) (Storage, error)

func NewAzure

func NewAzure(conf *AzureConfig) (Storage, error)

NewAzure signs requests with the account key, or with TokenCredential where no key is set, as with a managed or workload identity.

func NewGCP

func NewGCP(conf *GCPConfig) (Storage, error)

func NewLocal

func NewLocal(conf *LocalConfig) (Storage, error)

func NewOCI

func NewOCI(conf *OCIConfig) (Storage, error)

NewOCI makes no request. With workload identity the SDK fetches a token as its client is built, so the first call builds it. A namespace the config leaves out is looked up by the first call as well.

func NewS3

func NewS3(conf *S3Config) (Storage, error)

Directories

Path Synopsis
objects module

Jump to

Keyboard shortcuts

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