base

package
v0.0.0-...-14a2f30 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package base provides a base implementation of the storage driver that can be used to implement common checks. The goal is to increase the amount of code sharing.

The canonical approach to use this class is to embed in the exported driver struct such that calls are proxied through this implementation. First, declare the internal driver, as follows:

type driver struct { ... internal ...}

The resulting type should implement StorageDriver such that it can be the target of a Base struct. The exported type can then be declared as follows:

type Driver struct {
	Base
}

Because Driver embeds Base, it effectively implements Base. If the driver needs to intercept a call, before going to base, Driver should implement that method. Effectively, Driver can intercept calls before coming in and driver implements the actual logic.

To further shield the embed from other packages, it is recommended to employ a private embed struct:

type baseEmbed struct {
	base.Base
}

Then, declare driver to embed baseEmbed, rather than Base directly:

type Driver struct {
	baseEmbed
}

The type now implements StorageDriver, proxying through Base, without exporting an unnecessary field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRegulator

func NewRegulator(driver storagedriver.StorageDriver, limit uint64) storagedriver.StorageDriver

NewRegulator wraps the given driver and is used to regulate concurrent calls to the given storage driver to a maximum of the given limit. This is useful for storage drivers that would otherwise create an unbounded number of OS threads if allowed to be called unregulated.

Types

type Base

type Base struct {
	storagedriver.StorageDriver
}

Base provides a wrapper around a storagedriver implementation that provides common path and bounds checking.

func (*Base) Delete

func (base *Base) Delete(ctx context.Context, path string) error

Delete wraps Delete of underlying storage driver.

func (*Base) GetContent

func (base *Base) GetContent(ctx context.Context, path string) ([]byte, error)

GetContent wraps GetContent of underlying storage driver.

func (*Base) List

func (base *Base) List(ctx context.Context, path string) ([]string, error)

List wraps List of underlying storage driver.

func (*Base) Move

func (base *Base) Move(ctx context.Context, sourcePath string, destPath string) error

Move wraps Move of underlying storage driver.

func (*Base) PutContent

func (base *Base) PutContent(ctx context.Context, path string, content []byte) error

PutContent wraps PutContent of underlying storage driver.

func (*Base) Reader

func (base *Base) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error)

Reader wraps Reader of underlying storage driver.

func (*Base) Stat

func (base *Base) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error)

Stat wraps Stat of underlying storage driver.

func (*Base) URLFor

func (base *Base) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error)

URLFor wraps URLFor of underlying storage driver.

func (*Base) Writer

func (base *Base) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error)

Writer wraps Writer of underlying storage driver.

Jump to

Keyboard shortcuts

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