backend

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package backend proides the backends used by fake-gcs-server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket added in v1.16.0

type Bucket struct {
	Name              string
	VersioningEnabled bool
	TimeCreated       time.Time
}

Bucket represents the bucket that is stored within the fake server.

type Object

type Object struct {
	BucketName      string `json:"-"`
	Name            string `json:"-"`
	ContentType     string
	ContentEncoding string
	Content         []byte
	Crc32c          string
	Md5Hash         string
	ACL             []storage.ACLRule
	Metadata        map[string]string
	Created         string
	Deleted         string
	Updated         string
	Generation      int64
}

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

func (*Object) IDNoGen added in v1.16.0

func (o *Object) IDNoGen() string

IDNoGen does not consider the generation field

type Storage

type Storage interface {
	CreateBucket(name string, versioningEnabled bool) error
	ListBuckets() ([]Bucket, error)
	GetBucket(name string) (Bucket, error)
	CreateObject(obj Object) error
	ListObjects(bucketName string, versions bool) ([]Object, error)
	GetObject(bucketName, objectName string) (Object, error)
	GetObjectWithGeneration(bucketName, objectName string, generation int64) (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, versioningEnabled bool) 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) (Bucket, 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) GetObjectWithGeneration added in v1.16.0

func (s *StorageFS) GetObjectWithGeneration(bucketName, objectName string, generation int64) (Object, error)

GetObjectWithGeneration retrieves an specific version of the object. Not implemented

func (*StorageFS) ListBuckets

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

ListBuckets lists buckets

func (*StorageFS) ListObjects

func (s *StorageFS) ListObjects(bucketName string, versions bool) ([]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, versioningEnabled bool) 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) (Bucket, 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) GetObjectWithGeneration added in v1.16.0

func (s *StorageMemory) GetObjectWithGeneration(bucketName, objectName string, generation int64) (Object, error)

GetObjectWithGeneration retrieves an specific version of the object

func (*StorageMemory) ListBuckets

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

ListBuckets lists buckets

func (*StorageMemory) ListObjects

func (s *StorageMemory) ListObjects(bucketName string, versions bool) ([]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