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 ¶
- 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) ReadStream(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) WriteStream(ctx context.Context, path string, offset int64, reader io.Reader) (nn int64, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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) ReadStream ¶
ReadStream wraps ReadStream of underlying storage driver.