storage

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAliyun

func NewAliyun(c *Config) oss.StorageInterface

NewAliyun new aliyun oss

func NewAzure

func NewAzure(c *Config) oss.StorageInterface

NewAzure new azure blob storage

func NewMinio

func NewMinio(c *Config) oss.StorageInterface

NewMinio new minio

func NewS3

func NewS3(c *Config) oss.StorageInterface

NewS3 new aws s3

func NewStorage

func NewStorage(c *Config) (oss.StorageInterface, error)

NewStorage new storage

func NewTencentCloud

func NewTencentCloud(c *Config) oss.StorageInterface

NewTencentCloud new tencent cloud cos

func RestoreOriginalFileName

func RestoreOriginalFileName(uniqueName string, withExt ...bool) string

RestoreOriginalFileName restores the original file name by removing the unique suffix. If withExt is true, it preserves the file extension.

Types

type Config

type Config struct {
	Provider string
	ID       string
	Secret   string
	Region   string
	Bucket   string
	Endpoint string
}

Config config

func GetConfig

func GetConfig(v *viper.Viper) *Config

GetConfig get storage config

type FileConfig

type FileConfig struct {
	Path      string     `json:"path"`
	MaxSize   int64      `json:"max_size"`
	AllowType []FileType `json:"allow_type"`
}

FileConfig file config

type FileHeader

type FileHeader struct {
	Name     string                `json:"name"`
	Size     int                   `json:"size"`
	Path     string                `json:"path"`
	Type     string                `json:"type"`
	Ext      string                `json:"ext"`
	Raw      *multipart.FileHeader `json:"raw"`
	Metadata any                   `json:"metadata,omitempty"`
}

FileHeader file header

func GetFileHeader

func GetFileHeader(f *multipart.FileHeader, prefix ...string) *FileHeader

GetFileHeader gets file header data and handles file renaming to ensure uniqueness

type FileSystem

type FileSystem interface {
	GetFullPath(p string) string
	Get(p string) (*os.File, error)
	GetStream(p string) (io.ReadCloser, error)
	Put(p string, r io.Reader) (*oss.Object, error)
	Delete(p string) error
	List(p string) ([]*oss.Object, error)
	GetEndpoint() string
	GetURL(p string) (string, error)
}

FileSystem represents the interface for file system storage.

type FileType

type FileType string

FileType file type

const (
	FileTypeFile    FileType = "file"
	FileTypeImage   FileType = "image"
	FileTypeVideo   FileType = "video"
	FileTypeAudio   FileType = "audio"
	FileTypeDoc     FileType = "doc"
	FileTypeArchive FileType = "archive"
	FileTypeOther   FileType = "other"
)

supported file types

type ImageConfig

type ImageConfig struct {
	Path      string          `json:"path"`
	MaxSize   int64           `json:"max_size"`
	Thumbnail ThumbnailConfig `json:"thumbnail"`
}

ImageConfig image config

type LocalFileSystem

type LocalFileSystem struct {
	Folder string
}

LocalFileSystem implements the FileSystem interface for local file system storage.

func NewFileSystem

func NewFileSystem(folder string) *LocalFileSystem

NewFileSystem creates a new local file system storage. It ensures the folder exists; if not, it creates the folder.

func (*LocalFileSystem) Delete

func (fs *LocalFileSystem) Delete(p string) error

Delete deletes a file.

func (*LocalFileSystem) Get

func (fs *LocalFileSystem) Get(p string) (*os.File, error)

Get receives a file with the given path.

func (*LocalFileSystem) GetEndpoint

func (fs *LocalFileSystem) GetEndpoint() string

GetEndpoint gets the endpoint. For FileSystem, the endpoint is "/".

func (*LocalFileSystem) GetFullPath

func (fs *LocalFileSystem) GetFullPath(p string) string

GetFullPath returns the full path from absolute / relative path.

func (*LocalFileSystem) GetStream

func (fs *LocalFileSystem) GetStream(p string) (io.ReadCloser, error)

GetStream gets a file as a stream.

func (*LocalFileSystem) GetURL

func (fs *LocalFileSystem) GetURL(p string) (string, error)

GetURL gets the public accessible URL.

func (*LocalFileSystem) List

func (fs *LocalFileSystem) List(p string) ([]*oss.Object, error)

List lists files.

func (*LocalFileSystem) Put

func (fs *LocalFileSystem) Put(p string, r io.Reader) (*oss.Object, error)

Put stores the reader into the given path.

type ThumbnailConfig

type ThumbnailConfig struct {
	Path      string `json:"path"`
	MaxWidth  int64  `json:"max_width"`
	MaxHeight int64  `json:"max_height"`
}

ThumbnailConfig thumbnail config

Jump to

Keyboard shortcuts

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