base

package
v2.0.0-rc.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2015 License: Apache-2.0 Imports: 3 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 unnessecary field.

Index

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) Delete

func (base *Base) Delete(path string) error

Delete wraps Delete of underlying storage driver.

func (*Base) GetContent

func (base *Base) GetContent(path string) ([]byte, error)

GetContent wraps GetContent of underlying storage driver.

func (*Base) List

func (base *Base) List(path string) ([]string, error)

List wraps List of underlying storage driver.

func (*Base) Move

func (base *Base) Move(sourcePath string, destPath string) error

Move wraps Move of underlying storage driver.

func (*Base) PutContent

func (base *Base) PutContent(path string, content []byte) error

PutContent wraps PutContent of underlying storage driver.

func (*Base) ReadStream

func (base *Base) ReadStream(path string, offset int64) (io.ReadCloser, error)

ReadStream wraps ReadStream of underlying storage driver.

func (*Base) Stat

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

Stat wraps Stat of underlying storage driver.

func (*Base) URLFor

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

URLFor wraps URLFor of underlying storage driver.

func (*Base) WriteStream

func (base *Base) WriteStream(path string, offset int64, reader io.Reader) (nn int64, err error)

WriteStream wraps WriteStream of underlying storage driver.

Jump to

Keyboard shortcuts

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