store

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

store

Tests

# test os store
go test -v -run=TestOSStore

# test s3 store
export S3_STORE_CONFIG=s3-config.json
go test -v -run=TestS3Store

# test qiniu store
export QINIU_STORE_CONFIG=qiniu-config.toml
go test -v -run=TestQiniuStore

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConfigured = fmt.Errorf("store is not configured")

	S3Env          = "S3_STORE_CONFIG"
	S3ReaderEnv    = "S3_READER_CONFIG"
	QiniuEnv       = "QINIU_STORE_CONFIG"
	QiniuReaderEnv = "QINIU_READER_CONFIG"
)
View Source
var (
	QiniuNotConfigError = fmt.Errorf("qiniu is not configured")
)
View Source
var (
	S3NotConfigError = fmt.Errorf("s3 store is not configured")
)

Functions

func IsUnionPath added in v0.0.3

func IsUnionPath(p string) bool

Types

type FileStat

type FileStat struct {
	Size int64
}

type Interface

type Interface interface {
	Stat(key string) (FileStat, error)
	UploadData(data []byte, key string) (err error)
	Upload(file string, key string) (err error)
	UploadReader(reader io.Reader, size int64, key string) (err error)
	DeleteDirectory(dir string) (err error)
	Delete(key string) (err error)
	Exists(key string) (bool, error)
	DownloadBytes(key string) ([]byte, error)
	DownloadReader(key string) (io.ReadCloser, error)
	DownloadRangeBytes(key string, offset int64, size int64) ([]byte, error)
	DownloadRangeReader(key string, offset int64, size int64) (io.ReadCloser, error)
	ListPrefix(key string) ([]string, error)
}

func NewMultiClusterQiniuStore added in v0.1.2

func NewMultiClusterQiniuStore() (Interface, error)

NewMultiClusterQiniuStore initializes a multi-cluster qiniu store, only support QINIU_MULTI_CLUSTER environment variable

func NewOSStore

func NewOSStore() Interface

func NewQiniuStore

func NewQiniuStore(cfgPath string) (Interface, error)

func NewS3Store

func NewS3Store(cfgPath string) (Interface, error)

func NewStore

func NewStore(qiniuConfigPath, s3ConfigPath string) (Interface, error)

type OSStore

type OSStore struct {
}

func (*OSStore) Delete

func (s *OSStore) Delete(key string) (err error)

Delete removes a file. with same behavior as os.Remove.

func (*OSStore) DeleteDirectory

func (s *OSStore) DeleteDirectory(dir string) (err error)

DeleteDirectory deletes a directory and all of its contents. If the directory is empty, return nil.

func (*OSStore) DownloadBytes

func (s *OSStore) DownloadBytes(key string) ([]byte, error)

func (*OSStore) DownloadRangeBytes

func (s *OSStore) DownloadRangeBytes(key string, offset int64, size int64) ([]byte, error)

func (*OSStore) DownloadRangeReader

func (s *OSStore) DownloadRangeReader(key string, offset int64, size int64) (io.ReadCloser, error)

func (*OSStore) DownloadReader

func (s *OSStore) DownloadReader(key string) (io.ReadCloser, error)

func (*OSStore) Exists

func (s *OSStore) Exists(key string) (bool, error)

Exists checks if a file exists.

func (*OSStore) ListPrefix

func (s *OSStore) ListPrefix(key string) (keys []string, err error)

func (*OSStore) Stat

func (s *OSStore) Stat(key string) (FileStat, error)

Stat returns a FileStat for the given key.

func (*OSStore) Upload

func (s *OSStore) Upload(file string, key string) (err error)

Upload "upload local file to local", it means just copy the file.

func (*OSStore) UploadData

func (s *OSStore) UploadData(data []byte, key string) (err error)

UploadData writes data to the given file. If the file already exists, it will return an error.

func (*OSStore) UploadReader

func (s *OSStore) UploadReader(reader io.Reader, _ int64, key string) (err error)

UploadReader writes the reader to a file.

type PathProtocol

type PathProtocol string
const (
	// QiniuProtocol is the protocol of Qiniu.
	// A file path should start with "qiniu://" or "qiniu:".
	// 1. qiniu://{host}/file/path
	// 2. qiniu:/file/path
	// Check https://en.wikipedia.org/wiki/File_URI_scheme
	QiniuProtocol   PathProtocol = "qiniu"
	S3Protocol      PathProtocol = "s3"
	OSProtocol      PathProtocol = ""
	UnknownProtocol PathProtocol = "Unknown"
)

func GetPathProtocol

func GetPathProtocol(p string) (PathProtocol, string, error)

func (PathProtocol) String

func (p PathProtocol) String() string

type QiniuStore

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

func (*QiniuStore) Delete

func (s *QiniuStore) Delete(key string) (err error)

Delete deletes a file from the Qiniu store.

func (*QiniuStore) DeleteDirectory

func (s *QiniuStore) DeleteDirectory(dir string) (err error)

DeleteDirectory deletes a directory from the Qiniu store.

func (*QiniuStore) DownloadBytes

func (s *QiniuStore) DownloadBytes(key string) ([]byte, error)

func (*QiniuStore) DownloadRangeBytes

func (s *QiniuStore) DownloadRangeBytes(key string, offset int64, size int64) ([]byte, error)

func (*QiniuStore) DownloadRangeReader

func (s *QiniuStore) DownloadRangeReader(key string, offset int64, size int64) (io.ReadCloser, error)

func (*QiniuStore) DownloadReader

func (s *QiniuStore) DownloadReader(key string) (io.ReadCloser, error)

func (*QiniuStore) Exists

func (s *QiniuStore) Exists(key string) (bool, error)

Exists returns true if the key exists in the Qiniu store.

func (*QiniuStore) ListPrefix

func (s *QiniuStore) ListPrefix(key string) ([]string, error)

func (*QiniuStore) Stat

func (s *QiniuStore) Stat(key string) (FileStat, error)

Stat returns the FileInfo for the named file.

func (*QiniuStore) Upload

func (s *QiniuStore) Upload(file string, key string) (err error)

Upload uploads a file to qiniu.

func (*QiniuStore) UploadData

func (s *QiniuStore) UploadData(data []byte, key string) (err error)

UploadData upload memory data to Qiniu store.

func (*QiniuStore) UploadReader

func (s *QiniuStore) UploadReader(reader io.Reader, _ int64, key string) (err error)

UploadReader upload reader to the Qiniu store.

type Reader added in v0.0.2

type Reader struct {
	Key    string
	Offset *int64
	Size   *int64
	// contains filtered or unexported fields
}

func NewReader added in v0.0.2

func NewReader(st Interface, key string, offset *int64, size *int64) *Reader

func (*Reader) Close added in v0.0.2

func (r *Reader) Close() error

func (*Reader) Read added in v0.0.2

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) Seek added in v0.0.2

func (r *Reader) Seek(_ int64, _ int) (int64, error)

func (*Reader) SeekStart added in v0.0.2

func (r *Reader) SeekStart() error

type S3Config

type S3Config struct {
	Endpoint  string `json:"endpoint" yaml:"endpoint" toml:"endpoint"`
	Region    string `json:"region" yaml:"region" toml:"region"`
	Bucket    string `json:"bucket" yaml:"bucket" toml:"bucket"`
	AccessKey string `json:"access_key" yaml:"access_key" toml:"access_key"`
	SecretKey string `json:"secret_key" yaml:"secret_key" toml:"secret_key"`
	Token     string `json:"token" yaml:"token" toml:"token"`
	UseSSL    bool   `json:"use_ssl" yaml:"use_ssl" toml:"use_ssl"`
}

func LoadS3Config

func LoadS3Config(cfgPath string) (*S3Config, error)

type S3Store

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

func (*S3Store) Delete

func (s *S3Store) Delete(key string) (err error)

Delete deletes the object. This is soft-delete operation, file will be renamed to recyclePath.

func (*S3Store) DeleteDirectory

func (s *S3Store) DeleteDirectory(dir string) (err error)

DeleteDirectory removes the directory from the s3 store. This is a soft-delete operation, all files will be renamed to .

func (*S3Store) DownloadBytes

func (s *S3Store) DownloadBytes(key string) ([]byte, error)

func (*S3Store) DownloadRangeBytes

func (s *S3Store) DownloadRangeBytes(key string, offset int64, size int64) ([]byte, error)

func (*S3Store) DownloadRangeReader

func (s *S3Store) DownloadRangeReader(key string, offset int64, size int64) (io.ReadCloser, error)

func (*S3Store) DownloadReader

func (s *S3Store) DownloadReader(key string) (io.ReadCloser, error)

func (*S3Store) Exists

func (s *S3Store) Exists(key string) (bool, error)

Exists checks if the object exists.

func (*S3Store) ListPrefix

func (s *S3Store) ListPrefix(key string) (keys []string, err error)

func (*S3Store) Stat

func (s *S3Store) Stat(key string) (FileStat, error)

func (*S3Store) Upload

func (s *S3Store) Upload(file string, key string) (err error)

func (*S3Store) UploadData

func (s *S3Store) UploadData(data []byte, key string) (err error)

func (*S3Store) UploadReader

func (s *S3Store) UploadReader(reader io.Reader, size int64, key string) (err error)

type Store

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

func (*Store) Delete

func (s *Store) Delete(key string) (err error)

func (*Store) DeleteDirectory

func (s *Store) DeleteDirectory(dir string) (err error)

func (*Store) DownloadBytes

func (s *Store) DownloadBytes(key string) (data []byte, err error)

func (*Store) DownloadRangeBytes

func (s *Store) DownloadRangeBytes(key string, offset int64, size int64) (data []byte, err error)

func (*Store) DownloadRangeReader

func (s *Store) DownloadRangeReader(key string, offset int64, size int64) (rc io.ReadCloser, err error)

func (*Store) DownloadReader

func (s *Store) DownloadReader(key string) (rc io.ReadCloser, err error)

func (*Store) Exists

func (s *Store) Exists(key string) (e bool, err error)

func (*Store) ListPrefix

func (s *Store) ListPrefix(key string) ([]string, error)

func (*Store) Stat

func (s *Store) Stat(key string) (fs FileStat, err error)

func (*Store) Upload

func (s *Store) Upload(file string, key string) (err error)

func (*Store) UploadData

func (s *Store) UploadData(data []byte, key string) (err error)

func (*Store) UploadReader

func (s *Store) UploadReader(reader io.Reader, size int64, key string) (err error)

Jump to

Keyboard shortcuts

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