Package base
import "github.com/docker/distribution/registry/storage/driver/base"
- Overview
- Index
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.
- func GetLimitFromParameter(param interface{}, min, def uint64) (uint64, error)
- func NewRegulator(driver storagedriver.StorageDriver, limit uint64) storagedriver.StorageDriver
- type Base
- func (base *Base) Delete(ctx context.Context, path string) error
- func (base *Base) GetContent(ctx context.Context, path string) ([]byte, error)
- func (base *Base) List(ctx context.Context, path string) ([]string, error)
- func (base *Base) Move(ctx context.Context, sourcePath string, destPath string) error
- func (base *Base) PutContent(ctx context.Context, path string, content []byte) error
- func (base *Base) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error)
- func (base *Base) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error)
- func (base *Base) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error)
- func (base *Base) Walk(ctx context.Context, path string, f storagedriver.WalkFn) error
- func (base *Base) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error)
Package files
base.go
regulator.go
func GetLimitFromParameter(param interface{}, min, def uint64) (uint64, error)
GetLimitFromParameter takes an interface type as decoded from the YAML
configuration and returns a uint64 representing the maximum number of
concurrent calls given a minimum limit and default.
If the parameter supplied is of an invalid type this returns an error.
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.
Base provides a wrapper around a storagedriver implementation that provides
common path and bounds checking.
type Base struct {
storagedriver.StorageDriver
}
func (base *Base) Delete(ctx context.Context, path string) error
Delete wraps Delete of underlying storage driver.
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 *Base) PutContent(ctx context.Context, path string, content []byte) error
PutContent wraps PutContent of underlying storage driver.
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 *Base) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error)
URLFor wraps URLFor of underlying storage driver.
func (*Base) Walk
¶
func (base *Base) Walk(ctx context.Context, path string, f storagedriver.WalkFn) error
Walk wraps Walk of underlying storage driver.
func (base *Base) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error)
Writer wraps Writer of underlying storage driver.