storage: Index | Files | Directories

package storage

import ""

Package storage offers generic (cloud) storage drivers.


Note that there are no mkdir/rmdir operations, although storage drivers should support subdirectories. Directory management is abstracted away in the backends that should attempt to purge empty directories.


Package Files

config.go glob.go memory.go storage.go


var ErrBadPattern = errors.New("syntax error in pattern")

ErrBadPattern indicates a pattern was malformed.

var (
    ErrConfigNil = errors.New("config can't be nil")

Common errors.

func ExistError Uses

func ExistError(op, path string) error

ExistError returns an error indicating that the file already exists. The error will pass os.IsExist.

func Glob Uses

func Glob(ctx context.Context, storage Storage, pattern string) (matches []string, err error)

Glob returns the names of all files matching pattern or nil if there is no matching file. The pattern may describe hierarchical names such as /usr/*/bin/ed.

Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.

The pattern syntax is:

	{ term }

	'*'         matches any sequence of non-Separator characters
	'?'         matches any single non-Separator character
	'[' [ '^' ] { character-range } ']'
	            character class (must be non-empty)
	c           matches character c (c != '*', '?', '\\', '[')
	'\\' c      matches character c

	c           matches character c (c != '\\', '-', ']')
	'\\' c      matches character c
	lo '-' hi   matches character c for lo <= c <= hi

func NotExistError Uses

func NotExistError(op, path string) error

NotExistError returns an error indicating that a file doesn't exist. The error will pass os.IsNotExist.

func PermissonError Uses

func PermissonError(op, path string) error

PermissonError returns an error indicating that there is a permission error accessing the file. The error will pass os.IsPermission.

func Register Uses

func Register(kind string, fn func() Opener)

Register a new storage type.

type Config Uses

type Config struct {
    Type   string                 `json:"type" yaml:"type"`
    Config map[string]interface{} `json:"config" yaml:"config"`

Config for a storage backend.

func (*Config) Open Uses

func (c *Config) Open() (Storage, error)

Open the storage backend.

type Opener Uses

type Opener interface {
    Open() (Storage, error)

Opener can open a new Storage.

type Storage Uses

type Storage interface {
    // Name gives a description of the storage.
    Name() string

    // Close the storage.
    Close() error

    // Save a file to the storage.
    Save(ctx context.Context, name string, r io.Reader) error

    // Open a file from storage for reading.
    Open(ctx context.Context, name string) (io.ReadCloser, error)

    // Create a file in storage for writing.
    Create(ctx context.Context, name string) (io.WriteCloser, error)

    // Readdir reads directory contents.
    Readdir(ctx context.Context, name string) ([]os.FileInfo, error)

    // Stat a file in storage.
    Stat(ctx context.Context, name string) (os.FileInfo, error)

    // Remove a file from storage.
    Remove(ctx context.Context, name string) error

Storage for named files. All paths in the supported storage use a backward slash ("/") as path separator.

func OpenMemory Uses

func OpenMemory() Storage

OpenMemory is an in-memory storage (for testing).


allPackage all loads all supported storage drivers.
diskPackage disk provides local disk storage.
ftpPackage ftp provides FTP storage.
googlePackage google provides Google Drive storage.
internal/obscurePackage obscure contains the Obscure and Reveal commands
oauth2Package oauth2 contains helper functions for provisioning OAuth2 tokens.
s3Package s3 provides S3 (and compatible) storage.
sftpPackage sftp provides SFTP storage.
webdavPackage webdav provides WebDAV (and compatible) storage.

Package storage imports 14 packages (graph) and is imported by 6 packages. Updated 2018-12-11. Refresh now. Tools for package owners.