storage

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: MIT Imports: 11 Imported by: 8

Documentation

Index

Constants

View Source
const (
	TypeMinio = StorageType("minio")
	TypeDisk  = StorageType("disk")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	StorageType     StorageType
	BaseDir         string
	Host            string
	Port            string
	SSL             bool
	AccessKeyID     string
	AccessKeySecret string
	Token           string
	Region          string
	MaxRetries      int
}

type DelParams

type DelParams struct {
	FullPath string
	Force    bool
}

type Interface

type Interface interface {
	// Put a file to storage.
	//
	// Errors:
	//
	// - `codes.CodeStorageNoFile`: if failed to put file to storage.
	Put(ctx context.Context, params PutParams) (PutResult, error)

	// Delete data from storage.
	//
	// Errors:
	//
	// - `codes.CodeStorageDelFailure`: if cannot delete file.
	Del(ctx context.Context, params DelParams) error

	// Generate url based on given full path of file.
	//
	// Errors:
	//
	// - `codes.CodeStorageGenerateURLFailure`: if failed on generate url.
	Url(ctx context.Context, params UrlParams) (UrlResult, error)
}

func Init added in v0.0.25

func Init(cfg Config) (Interface, error)

Initialize storage client.

Current supported storage types:

- minio: supported.

- disk: not implemented yet.

Will return error below if fail:

- `codes.CodeStorageNoClient`: cannot connect to client

func InitMinio

func InitMinio(cfg Config) (Interface, error)

Initialize minio object storage.

type PutParams

type PutParams struct {
	DirName                string
	FileName               string
	FileBuffer             io.Reader
	FileSize               int64
	ContentType            string
	ContentEncoding        string
	UserTags, UserMetadata map[string]string
}

type PutResult

type PutResult struct {
	DirName  string
	FileName string
	FullPath string
	Region   string
	Tag      string
	Size     int64
}

type StorageType added in v0.0.25

type StorageType string

type UrlParams

type UrlParams struct {
	FullPath       string
	ExpireDuration time.Duration
}

type UrlResult

type UrlResult struct {
	Scheme   string
	Host     string
	FullPath string
	FullURL  string
	RawQuery string
}

Jump to

Keyboard shortcuts

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