storage

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStorageNotInitialized = errors.New("storage not initialized")

Functions

func Delete

func Delete(path string) error

Delete 删除文件

func Exists

func Exists(path string) bool

Exists 检查文件是否存在

func Get

func Get(path string) ([]byte, error)

Get 获取文件内容

func GetURL

func GetURL(path string) string

GetURL 获取文件访问 URL

func Init

func Init(cfg *config.StorageConfig) error

Init 初始化存储

func SetStorage

func SetStorage(s Storage)

SetStorage 设置全局存储实例

func Upload

func Upload(file *multipart.FileHeader, subdir string) (string, error)

Upload 上传文件

func UploadFromBytes

func UploadFromBytes(data []byte, filename, subdir string) (string, error)

UploadFromBytes 从字节数组上传文件

Types

type LocalStorage

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

LocalStorage 本地存储

func NewLocalStorage

func NewLocalStorage(cfg *config.LocalStorageConfig) *LocalStorage

NewLocalStorage 创建本地存储实例

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(path string) error

Delete 删除文件

func (*LocalStorage) Exists

func (s *LocalStorage) Exists(path string) bool

Exists 检查文件是否存在

func (*LocalStorage) Get

func (s *LocalStorage) Get(path string) ([]byte, error)

Get 获取文件内容

func (*LocalStorage) GetURL

func (s *LocalStorage) GetURL(path string) string

GetURL 获取文件访问 URL

func (*LocalStorage) Upload

func (s *LocalStorage) Upload(file *multipart.FileHeader, subdir string) (string, error)

Upload 上传文件

func (*LocalStorage) UploadFromBytes

func (s *LocalStorage) UploadFromBytes(data []byte, filename, subdir string) (string, error)

UploadFromBytes 从字节数组上传文件

type OSSStorage

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

OSSStorage OSS 存储

func NewOSSStorage

func NewOSSStorage(cfg *config.OSSStorageConfig) (*OSSStorage, error)

NewOSSStorage 创建 OSS 存储实例

func (*OSSStorage) Delete

func (s *OSSStorage) Delete(path string) error

Delete 删除 OSS 文件

func (*OSSStorage) Exists

func (s *OSSStorage) Exists(path string) bool

Exists 检查 OSS 文件是否存在

func (*OSSStorage) Get

func (s *OSSStorage) Get(path string) ([]byte, error)

Get 获取 OSS 文件内容

func (*OSSStorage) GetSignedURL

func (s *OSSStorage) GetSignedURL(path string, expire time.Duration) (string, error)

GetSignedURL 获取带签名的临时访问 URL(用于私有文件)

func (*OSSStorage) GetURL

func (s *OSSStorage) GetURL(path string) string

GetURL 获取文件访问 URL

func (*OSSStorage) Upload

func (s *OSSStorage) Upload(file *multipart.FileHeader, subdir string) (string, error)

Upload 上传文件到 OSS

func (*OSSStorage) UploadFromBytes

func (s *OSSStorage) UploadFromBytes(data []byte, filename, subdir string) (string, error)

UploadFromBytes 从字节数组上传文件到 OSS

type Storage

type Storage interface {
	Upload(file *multipart.FileHeader, subdir string) (string, error)
	UploadFromBytes(data []byte, filename, subdir string) (string, error)
	GetURL(path string) string
	Delete(path string) error
	Get(path string) ([]byte, error)
	Exists(path string) bool
}

Storage 存储接口

func GetStorage

func GetStorage() Storage

GetStorage 获取全局存储实例

Jump to

Keyboard shortcuts

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