backend

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Object

type Object struct {
	BucketName string `json:"-"`
	Name       string `json:"-"`
	Content    []byte
	Crc32c     string
}

Object represents the object that is stored within the fake server.

func (*Object) ID

func (o *Object) ID() string

ID is useful for comparing objects

type Storage

type Storage interface {
	CreateBucket(name string) error
	ListBuckets() ([]string, error)
	GetBucket(name string) error
	CreateObject(obj Object) error
	ListObjects(bucketName string) ([]Object, error)
	GetObject(bucketName, objectName string) (Object, error)
	DeleteObject(bucketName, objectName string) error
}

Storage is the generic interface for implementing the backend storage of the server

func NewStorageFS

func NewStorageFS(objects []Object, rootDir string) (Storage, error)

NewStorageFS creates an instance of StorageMemory

func NewStorageMemory

func NewStorageMemory(objects []Object) Storage

NewStorageMemory creates an instance of StorageMemory

type StorageFS

type StorageFS struct {
	// contains filtered or unexported fields
}

StorageFS is an implementation of the backend storage that stores data on disk The layout is the following:

  • rootDir |- bucket1 \- bucket2 |- object1 \- object2

Bucket and object names are url path escaped, so there's no special meaning of forward slashes.

func (*StorageFS) CreateBucket

func (s *StorageFS) CreateBucket(name string) error

CreateBucket creates a bucket

func (*StorageFS) CreateObject

func (s *StorageFS) CreateObject(obj Object) error

CreateObject stores an object

func (*StorageFS) DeleteObject

func (s *StorageFS) DeleteObject(bucketName, objectName string) error

DeleteObject deletes an object by bucket and name

func (*StorageFS) GetBucket

func (s *StorageFS) GetBucket(name string) error

GetBucket checks if a bucket exists

func (*StorageFS) GetObject

func (s *StorageFS) GetObject(bucketName, objectName string) (Object, error)

GetObject get an object by bucket and name

func (*StorageFS) ListBuckets

func (s *StorageFS) ListBuckets() ([]string, error)

ListBuckets lists buckets

func (*StorageFS) ListObjects

func (s *StorageFS) ListObjects(bucketName string) ([]Object, error)

ListObjects lists the objects in a given bucket with a given prefix and delimeter

type StorageMemory

type StorageMemory struct {
	// contains filtered or unexported fields
}

StorageMemory is an implementation of the backend storage that stores data in memory

func (*StorageMemory) CreateBucket

func (s *StorageMemory) CreateBucket(name string) error

CreateBucket creates a bucket

func (*StorageMemory) CreateObject

func (s *StorageMemory) CreateObject(obj Object) error

CreateObject stores an object

func (*StorageMemory) DeleteObject

func (s *StorageMemory) DeleteObject(bucketName, objectName string) error

DeleteObject deletes an object by bucket and name

func (*StorageMemory) GetBucket

func (s *StorageMemory) GetBucket(name string) error

GetBucket checks if a bucket exists

func (*StorageMemory) GetObject

func (s *StorageMemory) GetObject(bucketName, objectName string) (Object, error)

GetObject get an object by bucket and name

func (*StorageMemory) ListBuckets

func (s *StorageMemory) ListBuckets() ([]string, error)

ListBuckets lists buckets

func (*StorageMemory) ListObjects

func (s *StorageMemory) ListObjects(bucketName string) ([]Object, error)

ListObjects lists the objects in a given bucket with a given prefix and delimeter

Jump to

Keyboard shortcuts

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