fileserver

package
v0.0.0-...-271e206 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCacheSizeGT      = 64 << 10
	DefaultUploadPartSize   = 5 << 20
	DefaultDownloadPartSize = 10 << 20
	DefaultMaxObjectSize    = 4 << 30
	MinPartSize             = s3manager.MinUploadPartSize
	DefaultConcurrency      = 3
	DefaultSignTTL          = 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchObjectStorage

type BatchObjectStorage interface {
	ObjectStorage
	BatchUpload(ctx context.Context, keys []string, readers []io.Reader, opts ...UploadOpt) error
	BatchDownload(ctx context.Context, keys []string, writers []io.WriterAt, opts ...DownloadOpt) error
	BatchRead(ctx context.Context, keys []string, opts ...DownloadOpt) ([]Reader, error)

	BatchSignDownloadReq(ctx context.Context, keys []string, opts ...SignOpt) (urls []string, headers []http.Header, err error)
	BatchSignUploadReq(ctx context.Context, keys []string, opts ...SignOpt) (urls []string, headers []http.Header, err error)
}

type DownloadOpt

type DownloadOpt = Opt

func DownloadWithBucket

func DownloadWithBucket(bucket string) DownloadOpt

func DownloadWithConcurrency

func DownloadWithConcurrency(concurrency int) DownloadOpt

func DownloadWithTimeout

func DownloadWithTimeout(timeout time.Duration) DownloadOpt

type DownloadOption

type DownloadOption = Option

func NewDownloadOption

func NewDownloadOption(opts ...DownloadOpt) *DownloadOption

type ObjectInfo

type ObjectInfo struct {
	FName     string
	FSize     int64
	FModTime  time.Time
	FMetadata map[string]string
}

ObjectInfo represents the metadata of an object.

func NewObjectInfo

func NewObjectInfo(name string, size int64, modTime time.Time, metadata map[string]string) *ObjectInfo

NewObjectInfo creates a new ObjectInfo.

func (*ObjectInfo) IsDir

func (o *ObjectInfo) IsDir() bool

func (*ObjectInfo) ModTime

func (o *ObjectInfo) ModTime() time.Time

func (*ObjectInfo) Mode

func (o *ObjectInfo) Mode() fs.FileMode

func (*ObjectInfo) Name

func (o *ObjectInfo) Name() string

func (*ObjectInfo) Size

func (o *ObjectInfo) Size() int64

func (*ObjectInfo) Sys

func (o *ObjectInfo) Sys() any

type ObjectStorage

type ObjectStorage interface {
	Stat(ctx context.Context, key string, opts ...StatOpt) (*ObjectInfo, error)
	Upload(ctx context.Context, key string, r io.Reader, opts ...UploadOpt) error
	Download(ctx context.Context, key string, w io.WriterAt, opts ...DownloadOpt) error
	Read(ctx context.Context, key string, opts ...DownloadOpt) (Reader, error)
	Remove(ctx context.Context, key string, opts ...RemoveOpt) error

	SignUploadReq(ctx context.Context, key string, opts ...SignOpt) (url string, header http.Header, err error)
	SignDownloadReq(ctx context.Context, key string, opts ...SignOpt) (url string, header http.Header, err error)
}

ObjectStorage defines the interface for object storage backend(e.g. S3, OSS, TOS etc.)

type Opt

type Opt func(*Option)

type Option

type Option struct {
	Bucket      string
	Concurrency int
	Timeout     time.Duration
}

func (*Option) ContextWithTimeout

func (o *Option) ContextWithTimeout(ctx context.Context) (context.Context, context.CancelFunc)

type Reader

type Reader interface {
	io.ReadCloser
	io.ReaderAt
}

func NopCloser

func NopCloser(r rr) Reader

type RemoveOpt

type RemoveOpt = Opt

func RemoveWithBucket

func RemoveWithBucket(bucket string) RemoveOpt

type RemoveOption

type RemoveOption = Option

func NewRemoveOption

func NewRemoveOption(opts ...RemoveOpt) *RemoveOption

type S3Client

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

func NewS3Client

func NewS3Client(cfg *S3Config) (*S3Client, error)

func (*S3Client) BatchDownload

func (c *S3Client) BatchDownload(ctx context.Context, keys []string, writers []io.WriterAt, opts ...DownloadOpt) error

func (*S3Client) BatchRead

func (c *S3Client) BatchRead(ctx context.Context, keys []string, opts ...DownloadOpt) ([]Reader, error)

func (*S3Client) BatchSignDownloadReq

func (c *S3Client) BatchSignDownloadReq(ctx context.Context, keys []string, opts ...SignOpt) ([]string, []http.Header, error)

func (*S3Client) BatchSignUploadReq

func (c *S3Client) BatchSignUploadReq(ctx context.Context, keys []string, opts ...SignOpt) ([]string, []http.Header, error)

func (*S3Client) BatchUpload

func (c *S3Client) BatchUpload(ctx context.Context, keys []string, readers []io.Reader, opts ...UploadOpt) error

func (*S3Client) Download

func (c *S3Client) Download(ctx context.Context, key string, writer io.WriterAt, opts ...DownloadOpt) error

func (*S3Client) Read

func (c *S3Client) Read(ctx context.Context, key string, opts ...DownloadOpt) (Reader, error)

func (*S3Client) Remove

func (c *S3Client) Remove(ctx context.Context, key string, opts ...RemoveOpt) error

func (*S3Client) SignDownloadReq

func (c *S3Client) SignDownloadReq(ctx context.Context, key string, opts ...SignOpt) (url string, header http.Header, err error)

func (*S3Client) SignUploadReq

func (c *S3Client) SignUploadReq(ctx context.Context, key string, opts ...SignOpt) (url string, header http.Header, err error)

func (*S3Client) Stat

func (c *S3Client) Stat(ctx context.Context, key string, opts ...StatOpt) (*ObjectInfo, error)

func (*S3Client) Upload

func (c *S3Client) Upload(ctx context.Context, key string, r io.Reader, opts ...UploadOpt) error

type S3Config

type S3Config struct {
	Endpoint        string `json:"endpoint" yaml:"endpoint"`
	Region          string `json:"region" yaml:"region"`
	Bucket          string `json:"bucket" yaml:"bucket" validate:"required"`
	AccessKeyID     string `json:"access_key_id" yaml:"access_key_id"`
	SecretAccessKey string `json:"secret_access_key" yaml:"secret_access_key"`

	// For download, if the size of the object is less than CacheSizeGT, it will be
	// read into memory, or else it will be downloaded to local file in parts.
	// Default is 64KB, must be greater than 0.
	CacheSizeGT int64 `json:"cache_size_gt" yaml:"cache_size_gt"`
	// For download, the size of each part. Default is 10MB, must be greater than 0.
	DownloadPartSize int64 `json:"download_part_size" yaml:"download_part_size"`
	// For upload, the size of each part. Default is 5MB, must be greater than 0.
	UploadPartSize int64 `json:"upload_part_size" yaml:"upload_part_size"`
	// The maximum size of the uploaded object. Default is 4GB, must be greater than
	// 0.
	MaxObjectSize int64 `json:"max_object_size" yaml:"max_object_size"`

	// If true, the path style will be used for the S3 endpoint.
	// If false, the virtual hosted-style will be used for the S3 endpoint.
	// Default is true.
	ForcePathStyle *bool `json:"force_path_style" yaml:"force_path_style"`
}

func NewS3Config

func NewS3Config(opts ...S3Option) *S3Config

func (*S3Config) Validate

func (c *S3Config) Validate() error

type S3Option

type S3Option func(*S3Config)

type SignOpt

type SignOpt func(*SignOption)

func SignWithBucket

func SignWithBucket(bucket string) SignOpt

SignWithBucket specifies the bucket for the signed URL. Default bucket is the bucket of the object storage.

func SignWithFormat

func SignWithFormat(format string) SignOpt

SignWithFormat sets the format for the signed URL. Notice: not all backends support this option.

func SignWithImageTemplate

func SignWithImageTemplate(template string) SignOpt

SignWithImageTemplate sets the image template for the signed URL. Notice: not all backends support this option.

func SignWithTTL

func SignWithTTL(ttl time.Duration) SignOpt

SignWithTTL specifies the TTL for the signed URL. Default TTL is 24 hours.

type SignOption

type SignOption struct {
	Bucket        string
	ImageTemplate string
	Format        string
	TTL           time.Duration
}

func NewSignOption

func NewSignOption(opts ...SignOpt) *SignOption

type StatOpt

type StatOpt = Opt

func StatWithBucket

func StatWithBucket(bucket string) StatOpt

type StatOption

type StatOption = Option

func NewStatOption

func NewStatOption(opts ...StatOpt) *StatOption

type UploadOpt

type UploadOpt func(*UploadOption)

func UploadWithBucket

func UploadWithBucket(bucket string) UploadOpt

UploadWithBucket specifies the bucket for the upload. Default bucket is the bucket of the object storage.

func UploadWithConcurrency

func UploadWithConcurrency(concurrency int) UploadOpt

UploadWithConcurrency sets the concurrency for the upload. Default concurrency is 3, used in batch upload.

func UploadWithContentType

func UploadWithContentType(contentTypes ...string) UploadOpt

UploadWithContentType sets the content_type for the upload. Default content_type is None.

func UploadWithMetadata

func UploadWithMetadata(metadata map[string]string) UploadOpt

UploadWithMetadata sets the metadata for the uploaded object.

type UploadOption

type UploadOption struct {
	Bucket       string
	Metadata     map[string]string
	Concurrency  int
	ContentTypes []string
}

func NewUploadOption

func NewUploadOption(opts ...UploadOpt) *UploadOption

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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