storage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudinaryProvider

type CloudinaryProvider struct {
}

CloudinaryProvider Cloudinary 存储提供者(接口定义)

type DeleteInput

type DeleteInput struct {
	Filename string
	Folder   string
}

DeleteInput 删除输入

type FileInfo

type FileInfo struct {
	Name      string
	Size      int64
	IsDir     bool
	UpdatedAt int64
	Metadata  map[string]interface{}
}

FileInfo 文件信息

type GetSignedURLInput

type GetSignedURLInput struct {
	Filename string
	Folder   string
	Expires  int64 // 过期时间(秒)
}

GetSignedURLInput 获取签名 URL 输入

type GetURLInput

type GetURLInput struct {
	Filename string
	Folder   string
}

GetURLInput 获取 URL 输入

type ListInput

type ListInput struct {
	Folder string
	Prefix string
	Limit  int
}

ListInput 列表输入

type LocalProvider

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

LocalProvider implements storage.Provider for local filesystem

func NewLocalProvider

func NewLocalProvider(basePath, baseURL string) (*LocalProvider, error)

NewLocalProvider creates a new local storage provider

func (*LocalProvider) Delete

func (p *LocalProvider) Delete(ctx context.Context, input DeleteInput) error

Delete removes a file from the local filesystem

func (*LocalProvider) Exists

func (p *LocalProvider) Exists(ctx context.Context, path string) (bool, error)

Exists checks if a file exists

func (*LocalProvider) GetSignedURL

func (p *LocalProvider) GetSignedURL(ctx context.Context, input GetSignedURLInput) (string, error)

GetSignedURL for local provider just returns the public URL

func (*LocalProvider) GetURL

func (p *LocalProvider) GetURL(ctx context.Context, input GetURLInput) (string, error)

GetURL returns the public URL for a file

func (*LocalProvider) Name

func (p *LocalProvider) Name() string

func (*LocalProvider) Upload

func (p *LocalProvider) Upload(ctx context.Context, file io.Reader, path string) (string, error)

Upload saves a file to the local filesystem

type LocalStorageProvider

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

LocalStorageProvider 本地存储提供者(使用新接口)

func NewLocalStorageProvider

func NewLocalStorageProvider(basePath, baseURL string) (*LocalStorageProvider, error)

NewLocalStorageProvider 创建本地存储提供者

func (*LocalStorageProvider) Delete

func (p *LocalStorageProvider) Delete(ctx context.Context, input DeleteInput) error

Delete 删除文件

func (*LocalStorageProvider) GetSignedURL

func (p *LocalStorageProvider) GetSignedURL(ctx context.Context, input GetSignedURLInput) (string, error)

GetSignedURL 获取签名 URL(本地存储不需要签名)

func (*LocalStorageProvider) GetURL

func (p *LocalStorageProvider) GetURL(ctx context.Context, input GetURLInput) (string, error)

GetURL 获取文件 URL

func (*LocalStorageProvider) List

func (p *LocalStorageProvider) List(ctx context.Context, input ListInput) ([]FileInfo, error)

List 列出文件

func (*LocalStorageProvider) Move

func (p *LocalStorageProvider) Move(ctx context.Context, input MoveInput) error

Move 移动文件

func (*LocalStorageProvider) Upload

Upload 上传文件

type MoveInput

type MoveInput struct {
	Source      string
	Destination string
}

MoveInput 移动输入

type OSSProvider

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

OSSProvider implements storage.Provider for Aliyun OSS

func NewOSSProvider

func NewOSSProvider(endpoint, accessKeyID, accessKeySecret, bucketName, domain string) (*OSSProvider, error)

NewOSSProvider creates a new OSS storage provider Endpoint: oss-cn-hangzhou.aliyuncs.com

func (*OSSProvider) Delete

func (p *OSSProvider) Delete(ctx context.Context, path string) error

Delete removes a file from OSS

func (*OSSProvider) Exists

func (p *OSSProvider) Exists(ctx context.Context, path string) (bool, error)

Exists checks if a file exists in OSS

func (*OSSProvider) GetSignedURL

func (p *OSSProvider) GetSignedURL(ctx context.Context, path string, expiry time.Duration) (string, error)

GetSignedURL generates a signed URL for private object access

func (*OSSProvider) Name

func (p *OSSProvider) Name() string

func (*OSSProvider) Upload

func (p *OSSProvider) Upload(ctx context.Context, file io.Reader, path string) (string, error)

Upload saves a file to OSS

type ProviderConfig

type ProviderConfig struct {
	Type     string                 `json:"type"`     // local, s3, cloudinary
	Settings map[string]interface{} `json:"settings"` // 各提供者特定配置
}

ProviderConfig 提供者配置

type ProviderFactory

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

ProviderFactory 提供者工厂

func NewProviderFactory

func NewProviderFactory() *ProviderFactory

NewProviderFactory 创建工厂

func (*ProviderFactory) CreateFromConfig

func (f *ProviderFactory) CreateFromConfig(config ProviderConfig) (StorageProvider, error)

CreateFromConfig 从配置创建提供者

func (*ProviderFactory) Get

func (f *ProviderFactory) Get(name string) (StorageProvider, error)

Get 获取提供者

func (*ProviderFactory) Register

func (f *ProviderFactory) Register(name string, provider StorageProvider)

Register 注册提供者

type S3Provider

type S3Provider struct {
}

S3Provider S3 存储提供者(接口定义,具体实现需要 AWS SDK)

type StorageProvider

type StorageProvider interface {
	Upload(ctx context.Context, input UploadInput) (UploadOutput, error)
	Delete(ctx context.Context, input DeleteInput) error
	GetURL(ctx context.Context, input GetURLInput) (string, error)
	GetSignedURL(ctx context.Context, input GetSignedURLInput) (string, error)
	Move(ctx context.Context, input MoveInput) error
	List(ctx context.Context, input ListInput) ([]FileInfo, error)
}

StorageProvider 存储提供者接口

type UploadInput

type UploadInput struct {
	File      io.Reader
	Filename  string
	Folder    string
	IsPrivate bool
	Metadata  map[string]interface{}
	Size      int64
}

UploadInput 上传输入

type UploadOutput

type UploadOutput struct {
	URL      string
	Filename string
	Size     int64
	Metadata map[string]interface{}
}

UploadOutput 上传输出

Jump to

Keyboard shortcuts

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