multi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package multi provides fan-out writing to multiple backends simultaneously.

The multi-writer allows writing the same data to multiple storage backends at once, useful for:

  • Replication across storage providers
  • Writing to both local and remote storage
  • Backup during write operations
  • Testing with multiple backends

Example usage:

// Create backends
local := memory.New()
s3Backend, _ := s3.New(config)
gcsBackend, _ := gcs.New(config)

// Create multi-writer
mw := multi.NewWriter(local, s3Backend, gcsBackend)

// Write to all backends simultaneously
w, _ := mw.NewWriter(ctx, "data/file.json")
w.Write([]byte(`{"key": "value"}`))
w.Close()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiError

type MultiError struct {
	Errors []error
}

MultiError represents multiple errors from multi-backend operations.

func (*MultiError) All

func (e *MultiError) All() []error

All returns all errors.

func (*MultiError) Error

func (e *MultiError) Error() string

Error implements the error interface.

func (*MultiError) Unwrap

func (e *MultiError) Unwrap() error

Unwrap returns the first error for errors.Is/As compatibility.

type Option

type Option func(*Writer)

Option configures a multi-writer.

func WithMode

func WithMode(mode WriteMode) Option

WithMode sets the write mode.

type WriteMode

type WriteMode int

WriteMode determines how the multi-writer handles failures.

const (
	// WriteAll requires all backends to succeed.
	// If any backend fails, the entire write fails.
	WriteAll WriteMode = iota

	// WriteBestEffort writes to all backends but continues on failure.
	// Errors are collected and returned, but writing continues.
	WriteBestEffort

	// WriteQuorum requires a majority of backends to succeed.
	WriteQuorum
)

type Writer

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

Writer provides fan-out writing to multiple backends.

func NewWriter

func NewWriter(backends ...omnistorage.Backend) (*Writer, error)

NewWriter creates a new multi-writer for the given backends. At least one backend must be provided.

func NewWriterWithOptions

func NewWriterWithOptions(backends []omnistorage.Backend, opts ...Option) (*Writer, error)

NewWriterWithOptions creates a new multi-writer with options.

func (*Writer) Backends

func (w *Writer) Backends() int

Backends returns the number of backends.

func (*Writer) NewWriter

func (w *Writer) NewWriter(ctx context.Context, path string, opts ...omnistorage.WriterOption) (io.WriteCloser, error)

NewWriter creates a writer that fans out to all backends.

Jump to

Keyboard shortcuts

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