Documentation ¶
Overview ¶
Package storage provides types and functionality for abstracting storage systems (Local, in memory, S3, Google Cloud storage) into a common interface.
Index ¶
- Constants
- Variables
- func IsNotExist(err error) bool
- func List(ctx context.Context, w Walker, path string) ([]string, error)
- func WalkN(ctx context.Context, w Walker, path string, n int, fn WalkFn) error
- type CloudStorage
- func (c *CloudStorage) Create(ctx context.Context, path string) (io.WriteCloser, error)
- func (c *CloudStorage) Delete(ctx context.Context, path string) error
- func (c *CloudStorage) Open(ctx context.Context, path string) (*File, error)
- func (c *CloudStorage) Walk(ctx context.Context, path string, fn WalkFn) error
- type ErrCountFS
- func (s ErrCountFS) Create(ctx context.Context, path string) (io.WriteCloser, error)
- func (s ErrCountFS) Delete(ctx context.Context, path string) error
- func (s ErrCountFS) Open(ctx context.Context, path string) (*File, error)
- func (s ErrCountFS) Walk(ctx context.Context, path string, fn WalkFn) error
- type FS
- type File
- type GetSetter
- type Local
- type LogFS
- type S3
- type TraceFS
- func (t *TraceFS) Create(ctx context.Context, path string) (wc io.WriteCloser, err error)
- func (t *TraceFS) Delete(ctx context.Context, path string) (err error)
- func (t *TraceFS) Open(ctx context.Context, path string) (f *File, err error)
- func (t *TraceFS) Walk(ctx context.Context, path string, fn WalkFn) error
- type WalkFn
- type Walker
Constants ¶
const DefaultLocalCreatePathMode = os.FileMode(0755)
DefaultLocalCreatePathMode is the default os.FileMode used when creating directories during a Local.Create call.
Variables ¶
var LocalCreatePathMode = DefaultLocalCreatePathMode
LocalCreatePathMode is the os.FileMode used when creating directories via Local.Create
Functions ¶
func IsNotExist ¶
IsNotExist returns a boolean indicating whether the error is known to report that a path does not exist.
Types ¶
type CloudStorage ¶
type CloudStorage struct {
Bucket string
}
CloudStorage implements FS and uses Google Cloud Storage as the underlying file storage.
func (*CloudStorage) Create ¶
func (c *CloudStorage) Create(ctx context.Context, path string) (io.WriteCloser, error)
Create implements FS.
func (*CloudStorage) Delete ¶
func (c *CloudStorage) Delete(ctx context.Context, path string) error
Delete implements FS.
type ErrCountFS ¶
type ErrCountFS struct {
// contains filtered or unexported fields
}
ErrCountFS is an FS which records error counts for an FS.
func NewErrCountFS ¶
func NewErrCountFS(fs FS, name string, err error) *ErrCountFS
NewErrCountFS creates an FS which records stats based on usage.
func (ErrCountFS) Create ¶
func (s ErrCountFS) Create(ctx context.Context, path string) (io.WriteCloser, error)
Create implements FS. All errors from Create are counted.
func (ErrCountFS) Delete ¶
func (s ErrCountFS) Delete(ctx context.Context, path string) error
Delete implements FS. All errors from Delete are counted.
type FS ¶
type FS interface { Walker // Open opens an existing file at path in the filesystem. Callers must close the // File when done to release all underlying resources. Open(ctx context.Context, path string) (*File, error) // Create makes a new file at path in the filesystem. Callers must close the // returned WriteCloser and check the error to be sure that the file // was successfully written. Create(ctx context.Context, path string) (io.WriteCloser, error) // Delete removes a path from the filesystem. Delete(ctx context.Context, path string) error }
FS is an interface which defines a virtual filesystem.
func FSFromURL ¶
FSFromURL takes a file system path and returns a FSWalker corresponding to a supported storage system (CloudStorage, S3, or Local if no platform-specific prefix is used).
type File ¶
type File struct { io.ReadCloser // Underlying data. Name string // Name of the file (likely basename). ModTime time.Time // Modified time of the file. Size int64 // Size of the file. }
File contains the metadata required to define a file (for reading).
type GetSetter ¶
type GetSetter interface { Get(key string) (string, error) Set(key string, value string) error Delete(key string) error }
GetSetter implements a key-value store which is concurrency safe (can be used in multiple go-routines concurrently).
type Local ¶
type Local string
Local is a local FS and Walker implementation.
func (Local) Create ¶
Create implements FS. If the path contains any directories which do not already exist then Create will try to make them, returning an error if it fails.
type LogFS ¶
type LogFS struct {
// contains filtered or unexported fields
}
LogFS is an FS implementation which logs all filesystem calls.
func (*LogFS) Create ¶
Create implements FS. All calls to Create are logged and errors are logged seperately.
func (*LogFS) Delete ¶
Delete implements FS. All calls to Delete are logged and errors are logged seperately.
type S3 ¶
type S3 struct {
Bucket string // Bucket is the name of the bucket to use as the underlying storage.
}
S3 is an implementation of FS which uses AWS S3 as the underlying storage layer.
type TraceFS ¶
type TraceFS struct {
// contains filtered or unexported fields
}
TraceFS is a FS implementation which wraps an FS and records calls using golang.org/x/net/trace.
func NewTraceFS ¶
NewTraceFS creates a new FS which wraps an FS and records calls using golang.org/x/net/trace.
func (*TraceFS) Create ¶
Create implements FS. All calls to Create are logged via golang.org/x/net/trace.
func (*TraceFS) Delete ¶
Delete implements FS. All calls to Delete are logged via golang.org/x/net/trace.