core

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExistsDriver = errors.New("driver already exists")

ErrExistsDriver can not register same driver twice.

View Source
var ErrorConfigEmpty = errors.New("configuration not correct")

ErrorConfigEmpty is configuration empty error.

Functions

This section is empty.

Types

type Chunks

type Chunks interface {
	Chunk() (*ListObjectResult, error)
}

Chunks is used to get the next "page" of objects.

type Driver

type Driver interface {
	// Storage is the abstraction for cloud storage.
	Storage() (Storage, error)

	// Name is the name of provider.
	Name() string
}

Driver is the abstraction for different cloud storage service provider.

type File

type File interface {
	// Key is the object key.
	Key() string

	// Type is the object type.
	Type() string

	// Size is the size of current file.
	Size() int64

	// ETag is etag return by cloud storage providers.
	ETag() string

	// LastModified is the time when the object was last updated.
	LastModified() time.Time
}

File A slice of File is returned when all files are fetched through Storage.Files. File hides differences in object returns from different cloud storage providers, but at the same time, it can only return less information.

type FileIterator

type FileIterator interface {
	// All Get all objects.
	All() ([]File, error)
}

FileIterator is an iterator used to iterate over all objects in the cloud.

func NewFileIterator

func NewFileIterator(chunks Chunks) FileIterator

NewFileIterator creates an instance of FileIterator.

type Kernel

type Kernel struct {
	Storage Storage
	// contains filtered or unexported fields
}

Kernel is the core struct of goss, it plays the role of a driver manager.

func New

func New() Kernel

New create a new instance of Kernel.

func (*Kernel) RegisterDriver

func (a *Kernel) RegisterDriver(driver Driver) error

RegisterDriver is used to register new driver.

func (*Kernel) UseDriver

func (a *Kernel) UseDriver(driver Driver) error

UseDriver is used to switch to the specified driver.

type ListObjectResult

type ListObjectResult struct {
	Files      []File
	IsFinished bool
}

type Storage

type Storage interface {
	// Put saves the content read from r to the key of oss.
	Put(key string, r io.Reader) error

	// PutFromFile saves the file pointed to by the `localPath` to the oss key.
	PutFromFile(key string, localPath string) error

	// Get gets the file pointed to by key.
	Get(key string) (io.ReadCloser, error)

	// GetString gets the file pointed to by key and returns a string.
	GetString(key string) (string, error)

	// GetBytes gets the file pointed to by key and returns a byte array.
	GetBytes(key string) ([]byte, error)

	// GetToFile saves the file pointed to by key to the localPath.
	GetToFile(key string, localPath string) error

	// Delete the file pointed to by key.
	Delete(key string) error

	// Exists determines whether the file exists.
	Exists(key string) (bool, error)

	// Files list all files in the specified directory.
	Files(dir string) ([]File, error)

	// Size fet the file size.
	Size(key string) (int64, error)

	// Store is an instance for calling APIs of different cloud storage service providers.
	Store() interface{}
}

Storage defines a unified interface for reading and writing cloud storage objects.

func NewStorage

func NewStorage(store Store) Storage

NewStorage create new Storage instance.

type Storages

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

Storages store all supported drivers.

func (*Storages) Get

func (s *Storages) Get(name string) (Storage, error)

Get driver by name.

func (*Storages) Register

func (s *Storages) Register(name string, storage Storage) error

Register a new driver.

type Store

type Store interface {
	// Put reads the content of r, uploads it to cloud, and names it as key.
	Put(key string, r io.Reader) error

	// PutFromFile reads the content of localPath, uploads it to cloud, and names it as key.
	PutFromFile(key string, localPath string) error

	// Get gets the content of the object named key in cloud storage.
	Get(key string) (io.ReadCloser, error)

	// Delete deletes the contents of the file pointed to by key.
	Delete(key string) error

	// Size gets the size of the object pointed to by key.
	Size(key string) (int64, error)

	// Exists determines whether the object pointed to by key exists.
	Exists(key string) (bool, error)

	// Iterator gets a FileIterator based on prefix.
	Iterator(prefix string) FileIterator
}

Store is an abstraction layer for different cloud storage provider's APIs

Jump to

Keyboard shortcuts

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