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 ¶
- 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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLimitFromParameter ¶ added in v2.7.0
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 ¶ added in v2.5.0
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) GetContent ¶
GetContent wraps GetContent of underlying storage driver.
func (*Base) PutContent ¶
PutContent wraps PutContent 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 ¶ added in v2.4.0
func (base *Base) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error)
Writer wraps Writer of underlying storage driver.