Documentation
¶
Index ¶
- Variables
- func CalculateChecksum(data []byte, algorithm string) (string, error)
- func CalculateChecksumFromReader(reader io.Reader, algorithm string) (string, error)
- func ConvertToCoreFSFileSystem(storageFS FileSystem) core.FileSystem
- func ConvertToCoreWriteOptions(options []WriteOption) []core.WriteOption
- func DetectMimeType(filename string, data []byte) string
- type AfterUploadFunc
- type BatchProcessOptions
- type BatchProcessResult
- type BeforeUploadFunc
- type Cache
- type CacheManager
- func (cm *CacheManager) Exists(ctx context.Context, disk, path string) (bool, error)
- func (cm *CacheManager) Flush(ctx context.Context) error
- func (cm *CacheManager) GetContent(ctx context.Context, disk, path string) ([]byte, error)
- func (cm *CacheManager) GetFile(ctx context.Context, disk, path string) (File, error)
- func (cm *CacheManager) GetStream(ctx context.Context, disk, path string) (io.ReadCloser, error)
- func (cm *CacheManager) InvalidateCache(ctx context.Context, disk, path string) error
- func (cm *CacheManager) InvalidateCacheByPattern(ctx context.Context, disk, pattern string) error
- func (cm *CacheManager) IsEnabled() bool
- func (cm *CacheManager) SetEnabled(enabled bool)
- type CacheOptions
- type CachedFile
- func (f *CachedFile) Extension() string
- func (f *CachedFile) IsDirectory() bool
- func (f *CachedFile) LastModified() time.Time
- func (f *CachedFile) Metadata() map[string]interface{}
- func (f *CachedFile) MimeType() string
- func (f *CachedFile) Name() string
- func (f *CachedFile) Path() string
- func (f *CachedFile) Read(ctx context.Context) ([]byte, error)
- func (f *CachedFile) ReadStream(ctx context.Context) (io.ReadCloser, error)
- func (f *CachedFile) Size() int64
- func (f *CachedFile) TemporaryURL(ctx context.Context, expiration time.Duration) (string, error)
- func (f *CachedFile) URL() string
- func (f *CachedFile) Visibility() string
- type DiskConfig
- type File
- type FileAdapter
- func (f *FileAdapter) Extension() string
- func (f *FileAdapter) IsDirectory() bool
- func (f *FileAdapter) LastModified() time.Time
- func (f *FileAdapter) Metadata() map[string]interface{}
- func (f *FileAdapter) MimeType() string
- func (f *FileAdapter) Name() string
- func (f *FileAdapter) Path() string
- func (f *FileAdapter) Read(ctx context.Context) ([]byte, error)
- func (f *FileAdapter) ReadStream(ctx context.Context) (io.ReadCloser, error)
- func (f *FileAdapter) Size() int64
- func (f *FileAdapter) TemporaryURL(ctx context.Context, expiration time.Duration) (string, error)
- func (f *FileAdapter) URL() string
- func (f *FileAdapter) Visibility() string
- type FileConvertOptions
- type FileInfo
- type FileSystem
- type FileSystemAdapter
- func (fs *FileSystemAdapter) AllDirectories(ctx context.Context, directory string) ([]string, error)
- func (fs *FileSystemAdapter) AllFiles(ctx context.Context, directory string) ([]File, error)
- func (fs *FileSystemAdapter) Checksum(ctx context.Context, path string, algorithm string) (string, error)
- func (fs *FileSystemAdapter) Copy(ctx context.Context, source, destination string) error
- func (fs *FileSystemAdapter) CreateDirectory(ctx context.Context, path string, options ...WriteOption) error
- func (fs *FileSystemAdapter) Delete(ctx context.Context, path string) error
- func (fs *FileSystemAdapter) DeleteDirectory(ctx context.Context, path string) error
- func (fs *FileSystemAdapter) Directories(ctx context.Context, directory string) ([]string, error)
- func (fs *FileSystemAdapter) Exists(ctx context.Context, path string) (bool, error)
- func (fs *FileSystemAdapter) Files(ctx context.Context, directory string) ([]File, error)
- func (fs *FileSystemAdapter) Get(ctx context.Context, path string) (File, error)
- func (fs *FileSystemAdapter) LastModified(ctx context.Context, path string) (time.Time, error)
- func (fs *FileSystemAdapter) MimeType(ctx context.Context, path string) (string, error)
- func (fs *FileSystemAdapter) Move(ctx context.Context, source, destination string) error
- func (fs *FileSystemAdapter) SetVisibility(ctx context.Context, path, visibility string) error
- func (fs *FileSystemAdapter) Size(ctx context.Context, path string) (int64, error)
- func (fs *FileSystemAdapter) TemporaryURL(ctx context.Context, path string, expiration time.Duration) (string, error)
- func (fs *FileSystemAdapter) URL(ctx context.Context, path string) string
- func (fs *FileSystemAdapter) Visibility(ctx context.Context, path string) (string, error)
- func (fs *FileSystemAdapter) Write(ctx context.Context, path string, content []byte, options ...WriteOption) error
- func (fs *FileSystemAdapter) WriteStream(ctx context.Context, path string, content io.Reader, options ...WriteOption) error
- type FileValidator
- type ImageFormat
- type ImageResizeOptions
- type Manager
- func (m *Manager) AllFiles(ctx context.Context, directory string) ([]File, error)
- func (m *Manager) Copy(ctx context.Context, source, destination string) error
- func (m *Manager) CreateDirectory(ctx context.Context, path string, options ...WriteOption) error
- func (m *Manager) DefaultDisk() (FileSystem, error)
- func (m *Manager) Delete(ctx context.Context, path string) error
- func (m *Manager) DeleteDirectory(ctx context.Context, path string) error
- func (m *Manager) Directories(ctx context.Context, directory string) ([]string, error)
- func (m *Manager) Disk(name string) (FileSystem, error)
- func (m *Manager) Exists(ctx context.Context, path string) (bool, error)
- func (m *Manager) Files(ctx context.Context, directory string) ([]File, error)
- func (m *Manager) Get(ctx context.Context, path string) (File, error)
- func (m *Manager) GetDefaultDiskName() string
- func (m *Manager) GetDiskNames() []string
- func (m *Manager) HasDisk(name string) bool
- func (m *Manager) Move(ctx context.Context, source, destination string) error
- func (m *Manager) RegisterDisk(name string, fs interface{})
- func (m *Manager) SetDefaultDisk(name string) error
- func (m *Manager) TemporaryURL(ctx context.Context, path string, expiration time.Duration) (string, error)
- func (m *Manager) URL(ctx context.Context, path string) (string, error)
- func (m *Manager) UnregisterDisk(name string)
- func (m *Manager) Write(ctx context.Context, path string, content []byte, options ...WriteOption) error
- func (m *Manager) WriteStream(ctx context.Context, path string, content interface{}, options ...WriteOption) error
- type MemoryCache
- func (c *MemoryCache) Flush(ctx context.Context) error
- func (c *MemoryCache) FlushByPattern(ctx context.Context, pattern string) error
- func (c *MemoryCache) Forget(ctx context.Context, key string) error
- func (c *MemoryCache) Get(ctx context.Context, key string, value interface{}) (bool, error)
- func (c *MemoryCache) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- type Metadata
- func (m *Metadata) WithChecksum(checksum string) *Metadata
- func (m *Metadata) WithCustom(key string, value interface{}) *Metadata
- func (m *Metadata) WithIsDirectory(isDirectory bool) *Metadata
- func (m *Metadata) WithLastModified(lastModified time.Time) *Metadata
- func (m *Metadata) WithMimeType(mimeType string) *Metadata
- func (m *Metadata) WithSize(size int64) *Metadata
- func (m *Metadata) WithVisibility(visibility string) *Metadata
- type MigrationOptions
- type MigrationResult
- type Migrator
- func (m *Migrator) BatchCopy(ctx context.Context, disk string, sourceDirectory, targetDirectory string, ...) (*MigrationResult, error)
- func (m *Migrator) BatchMove(ctx context.Context, disk string, sourceDirectory, targetDirectory string, ...) (*MigrationResult, error)
- func (m *Migrator) Copy(ctx context.Context, disk, sourcePath, targetPath string) error
- func (m *Migrator) Migrate(ctx context.Context, sourceDisk, targetDisk string, sourceDirectory string, ...) (*MigrationResult, error)
- func (m *Migrator) Move(ctx context.Context, disk, sourcePath, targetPath string) error
- func (m *Migrator) Sync(ctx context.Context, sourceDisk, targetDisk string, directory string, ...) (*MigrationResult, error)
- type ProcessorManager
- func (pm *ProcessorManager) AddWatermark(ctx context.Context, sourcePath string, options *WatermarkOptions) (string, error)
- func (pm *ProcessorManager) BatchProcess(ctx context.Context, directory string, options *BatchProcessOptions) (*BatchProcessResult, error)
- func (pm *ProcessorManager) ConvertFile(ctx context.Context, sourcePath string, options *FileConvertOptions) (string, error)
- func (pm *ProcessorManager) ResizeImage(ctx context.Context, sourcePath string, options *ImageResizeOptions) (string, error)
- type Provider
- type StorageConfig
- type StorageToCoreFSAdapter
- func (fs *StorageToCoreFSAdapter) AllDirectories(ctx context.Context, directory string) ([]string, error)
- func (fs *StorageToCoreFSAdapter) AllFiles(ctx context.Context, directory string) ([]core.File, error)
- func (fs *StorageToCoreFSAdapter) Checksum(ctx context.Context, path string, algorithm string) (string, error)
- func (fs *StorageToCoreFSAdapter) Copy(ctx context.Context, source, destination string) error
- func (fs *StorageToCoreFSAdapter) CreateDirectory(ctx context.Context, path string, options ...core.WriteOption) error
- func (fs *StorageToCoreFSAdapter) Delete(ctx context.Context, path string) error
- func (fs *StorageToCoreFSAdapter) DeleteDirectory(ctx context.Context, path string) error
- func (fs *StorageToCoreFSAdapter) Directories(ctx context.Context, directory string) ([]string, error)
- func (fs *StorageToCoreFSAdapter) Exists(ctx context.Context, path string) (bool, error)
- func (fs *StorageToCoreFSAdapter) Files(ctx context.Context, directory string) ([]core.File, error)
- func (fs *StorageToCoreFSAdapter) Get(ctx context.Context, path string) (core.File, error)
- func (fs *StorageToCoreFSAdapter) LastModified(ctx context.Context, path string) (time.Time, error)
- func (fs *StorageToCoreFSAdapter) MimeType(ctx context.Context, path string) (string, error)
- func (fs *StorageToCoreFSAdapter) Move(ctx context.Context, source, destination string) error
- func (fs *StorageToCoreFSAdapter) SetVisibility(ctx context.Context, path, visibility string) error
- func (fs *StorageToCoreFSAdapter) Size(ctx context.Context, path string) (int64, error)
- func (fs *StorageToCoreFSAdapter) TemporaryURL(ctx context.Context, path string, expiration time.Duration) (string, error)
- func (fs *StorageToCoreFSAdapter) URL(ctx context.Context, path string) string
- func (fs *StorageToCoreFSAdapter) Visibility(ctx context.Context, path string) (string, error)
- func (fs *StorageToCoreFSAdapter) Write(ctx context.Context, path string, content []byte, options ...core.WriteOption) error
- func (fs *StorageToCoreFSAdapter) WriteStream(ctx context.Context, path string, content io.Reader, ...) error
- type StorageToCoreFSFileAdapter
- func (f *StorageToCoreFSFileAdapter) Extension() string
- func (f *StorageToCoreFSFileAdapter) IsDirectory() bool
- func (f *StorageToCoreFSFileAdapter) LastModified() time.Time
- func (f *StorageToCoreFSFileAdapter) Metadata() map[string]interface{}
- func (f *StorageToCoreFSFileAdapter) MimeType() string
- func (f *StorageToCoreFSFileAdapter) Name() string
- func (f *StorageToCoreFSFileAdapter) Path() string
- func (f *StorageToCoreFSFileAdapter) Read(ctx context.Context) ([]byte, error)
- func (f *StorageToCoreFSFileAdapter) ReadStream(ctx context.Context) (io.ReadCloser, error)
- func (f *StorageToCoreFSFileAdapter) Size() int64
- func (f *StorageToCoreFSFileAdapter) TemporaryURL(ctx context.Context, expiration time.Duration) (string, error)
- func (f *StorageToCoreFSFileAdapter) URL() string
- func (f *StorageToCoreFSFileAdapter) Visibility() string
- type UploadedFile
- type Uploader
- func (u *Uploader) AfterUpload(callback AfterUploadFunc) *Uploader
- func (u *Uploader) AllowMimeTypes(mimeTypes ...string) *Uploader
- func (u *Uploader) AllowOverwrite(allow bool) *Uploader
- func (u *Uploader) BeforeUpload(callback BeforeUploadFunc) *Uploader
- func (u *Uploader) GenerateUniqueName(generate bool) *Uploader
- func (u *Uploader) InDirectory(directory string) *Uploader
- func (u *Uploader) MaxFileSize(size int64) *Uploader
- func (u *Uploader) UploadFile(ctx context.Context, content []byte, filename string) (*UploadedFile, error)
- func (u *Uploader) UploadFromMultipartFile(ctx context.Context, file multipart.File, header *multipart.FileHeader) (*UploadedFile, error)
- func (u *Uploader) UploadFromRequest(ctx context.Context, r *http.Request, fieldName string) (*UploadedFile, error)
- func (u *Uploader) UploadMultiple(ctx context.Context, files map[string][]byte) ([]*UploadedFile, error)
- func (u *Uploader) UseDisk(disk string) *Uploader
- func (u *Uploader) WithCustomNamer(namer func(filename string) string) *Uploader
- func (u *Uploader) WithValidator(validator FileValidator) *Uploader
- func (u *Uploader) WithVisibility(visibility string) *Uploader
- type WatermarkOptions
- type WriteOption
- func ConvertToStorageWriteOptions(options []core.WriteOption) []WriteOption
- func WithMetadata(metadata map[string]interface{}) WriteOption
- func WithMimeType(mimeType string) WriteOption
- func WithOverwrite(overwrite bool) WriteOption
- func WithPermissions(permissions os.FileMode) WriteOption
- func WithVisibility(visibility string) WriteOption
- type WriteOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrFileNotFound = os.ErrNotExist ErrPermissionDenied = os.ErrPermission ErrInvalidPath = os.ErrInvalid ErrDirectoryNotEmpty = os.ErrExist ErrFileAlreadyExists = os.ErrExist )
常见错误定义
var ( ErrUnsupportedFileFormat = errors.New("processor: 不支持的文件格式") ErrProcessingFailed = errors.New("processor: 处理文件失败") ErrInvalidDimensions = errors.New("processor: 无效的图片尺寸") ErrInvalidOperation = errors.New("processor: 无效的操作") )
文件处理相关错误
Functions ¶
func CalculateChecksum ¶
CalculateChecksum 计算数据的校验和
func CalculateChecksumFromReader ¶
CalculateChecksumFromReader 从数据流计算校验和
func ConvertToCoreFSFileSystem ¶
func ConvertToCoreFSFileSystem(storageFS FileSystem) core.FileSystem
ConvertToCoreFSFileSystem 将storage.FileSystem转换为core.FileSystem
func ConvertToCoreWriteOptions ¶
func ConvertToCoreWriteOptions(options []WriteOption) []core.WriteOption
ConvertToCoreWriteOptions 将storage.WriteOption转换为core.WriteOption
func DetectMimeType ¶
DetectMimeType 尝试检测文件的MIME类型
Types ¶
type AfterUploadFunc ¶
type AfterUploadFunc func(ctx context.Context, file *UploadedFile, metadata *Metadata) error
AfterUploadFunc 上传后回调函数类型
type BatchProcessOptions ¶
type BatchProcessOptions struct {
// 处理类型: resize, watermark, convert
ProcessType string
// 处理选项
Options interface{}
// 文件匹配模式
Pattern string
// 是否递归处理子目录
Recursive bool
// 最大并发处理数
MaxConcurrent int
// 结果目录
ResultDirectory string
// 目标磁盘
TargetDisk string
}
BatchProcessOptions 批量处理选项
func DefaultBatchProcessOptions ¶
func DefaultBatchProcessOptions() *BatchProcessOptions
DefaultBatchProcessOptions 返回默认的批量处理选项
type BatchProcessResult ¶
type BatchProcessResult struct {
// 成功处理的文件路径
SuccessFiles []string
// 处理失败的文件及错误
FailedFiles map[string]error
// 处理的总文件数
TotalCount int
// 成功处理的文件数
SuccessCount int
// 处理失败的文件数
FailedCount int
}
BatchProcessResult 批量处理结果
type BeforeUploadFunc ¶
type BeforeUploadFunc func(ctx context.Context, file *UploadedFile) error
BeforeUploadFunc 上传前回调函数类型
type Cache ¶
type Cache interface {
// Get 从缓存获取值
Get(ctx context.Context, key string, value interface{}) (bool, error)
// Set 设置缓存值
Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
// Forget 删除缓存项
Forget(ctx context.Context, key string) error
// Flush 清空所有缓存
Flush(ctx context.Context) error
// FlushByPattern 按模式清空缓存
FlushByPattern(ctx context.Context, pattern string) error
}
Cache 缓存接口
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
CacheManager 文件缓存管理器
func NewCacheManager ¶
func NewCacheManager(manager *Manager, options *CacheOptions) *CacheManager
NewCacheManager 创建文件缓存管理器
func (*CacheManager) GetContent ¶
GetContent 获取文件内容(带缓存)
func (*CacheManager) GetStream ¶
func (cm *CacheManager) GetStream(ctx context.Context, disk, path string) (io.ReadCloser, error)
GetStream 获取文件流(带缓存)
func (*CacheManager) InvalidateCache ¶
func (cm *CacheManager) InvalidateCache(ctx context.Context, disk, path string) error
InvalidateCache 使缓存失效
func (*CacheManager) InvalidateCacheByPattern ¶
func (cm *CacheManager) InvalidateCacheByPattern(ctx context.Context, disk, pattern string) error
InvalidateCacheByPattern 按模式使缓存失效
func (*CacheManager) SetEnabled ¶
func (cm *CacheManager) SetEnabled(enabled bool)
SetEnabled 设置是否启用缓存
type CacheOptions ¶
type CacheOptions struct {
// 缓存实例
Cache Cache
// 缓存前缀
Prefix string
// 默认过期时间
DefaultTTL time.Duration
// 缓存目录(用于大文件本地缓存)
CacheDir string
// 是否开启缓存
Enabled bool
}
CacheOptions 缓存选项
type CachedFile ¶
type CachedFile struct {
// contains filtered or unexported fields
}
CachedFile 表示一个缓存的文件
func (*CachedFile) LastModified ¶
func (f *CachedFile) LastModified() time.Time
LastModified 返回文件的最后修改时间
func (*CachedFile) Metadata ¶
func (f *CachedFile) Metadata() map[string]interface{}
Metadata 获取文件的元数据
func (*CachedFile) Read ¶
func (f *CachedFile) Read(ctx context.Context) ([]byte, error)
Read 读取文件内容
func (*CachedFile) ReadStream ¶
func (f *CachedFile) ReadStream(ctx context.Context) (io.ReadCloser, error)
ReadStream 获取文件的读取流
func (*CachedFile) TemporaryURL ¶
TemporaryURL 获取文件的临时URL
type DiskConfig ¶
type DiskConfig struct {
// 驱动类型 (local, s3, etc.)
Driver string `mapstructure:"driver"`
// 驱动配置
Config map[string]interface{} `mapstructure:"config"`
}
DiskConfig 磁盘配置
type File ¶
type File interface {
// Path 返回文件的路径
Path() string
// Name 返回文件的名称(不包含路径)
Name() string
// Extension 返回文件的扩展名
Extension() string
// Size 返回文件的大小(字节)
Size() int64
// LastModified 返回文件的最后修改时间
LastModified() time.Time
// IsDirectory 判断是否为目录
IsDirectory() bool
// Read 读取文件内容
Read(ctx context.Context) ([]byte, error)
// ReadStream 获取文件的读取流
ReadStream(ctx context.Context) (io.ReadCloser, error)
// MimeType 返回文件的MIME类型
MimeType() string
// Visibility 返回文件的可见性(public 或 private)
Visibility() string
// URL 获取文件的URL(如果适用)
URL() string
// TemporaryURL 获取文件的临时URL(带有过期时间)
TemporaryURL(ctx context.Context, expiration time.Duration) (string, error)
// Metadata 获取文件的元数据
Metadata() map[string]interface{}
}
File 表示一个文件对象
func ConvertToStorageFile ¶
ConvertToStorageFile 将core.File转换为storage.File
func ConvertToStorageFiles ¶
ConvertToStorageFiles 将[]core.File转换为[]File
type FileAdapter ¶
FileAdapter 适配器,用于将core.File转换为storage.File
func (*FileAdapter) Extension ¶
func (f *FileAdapter) Extension() string
func (*FileAdapter) IsDirectory ¶
func (f *FileAdapter) IsDirectory() bool
func (*FileAdapter) LastModified ¶
func (f *FileAdapter) LastModified() time.Time
func (*FileAdapter) Metadata ¶
func (f *FileAdapter) Metadata() map[string]interface{}
func (*FileAdapter) MimeType ¶
func (f *FileAdapter) MimeType() string
func (*FileAdapter) Name ¶
func (f *FileAdapter) Name() string
func (*FileAdapter) ReadStream ¶
func (f *FileAdapter) ReadStream(ctx context.Context) (io.ReadCloser, error)
func (*FileAdapter) Size ¶
func (f *FileAdapter) Size() int64
func (*FileAdapter) TemporaryURL ¶
func (*FileAdapter) URL ¶
func (f *FileAdapter) URL() string
func (*FileAdapter) Visibility ¶
func (f *FileAdapter) Visibility() string
type FileConvertOptions ¶
type FileConvertOptions struct {
// 目标格式
TargetFormat string
// 转换参数
Parameters map[string]interface{}
// 是否保存原始文件
KeepOriginal bool
// 目标路径
TargetPath string
// 目标磁盘
TargetDisk string
}
FileConvertOptions 文件转换选项
func DefaultFileConvertOptions ¶
func DefaultFileConvertOptions() *FileConvertOptions
DefaultFileConvertOptions 返回默认的文件转换选项
type FileInfo ¶
type FileInfo struct {
// 文件路径
FilePath string `json:"path"`
// 文件名
FileName string `json:"name"`
// 文件大小(字节)
FileSize int64 `json:"size"`
// 是否为目录
IsDir bool `json:"is_directory"`
// 最后修改时间
ModTime time.Time `json:"modified_at"`
// MIME类型
ContentType string `json:"content_type"`
// 可见性
FileVisibility string `json:"visibility"`
// 元数据
MetaData map[string]interface{} `json:"metadata,omitempty"`
}
FileInfo 包含文件的基本信息
type FileSystem ¶
type FileSystem interface {
// Get 获取指定路径的文件
Get(ctx context.Context, path string) (File, error)
// Exists 检查文件是否存在
Exists(ctx context.Context, path string) (bool, error)
// Write 写入文件内容
Write(ctx context.Context, path string, content []byte, options ...WriteOption) error
// WriteStream 通过流写入文件
WriteStream(ctx context.Context, path string, content io.Reader, options ...WriteOption) error
// Delete 删除文件
Delete(ctx context.Context, path string) error
// DeleteDirectory 删除目录及其内容
DeleteDirectory(ctx context.Context, path string) error
// CreateDirectory 创建目录
CreateDirectory(ctx context.Context, path string, options ...WriteOption) error
// Files 列出目录下的所有文件
Files(ctx context.Context, directory string) ([]File, error)
// AllFiles 递归列出目录下的所有文件
AllFiles(ctx context.Context, directory string) ([]File, error)
// Directories 列出目录下的所有子目录
Directories(ctx context.Context, directory string) ([]string, error)
// AllDirectories 递归列出目录下的所有子目录
AllDirectories(ctx context.Context, directory string) ([]string, error)
// Copy 复制文件
Copy(ctx context.Context, source, destination string) error
// Move 移动文件
Move(ctx context.Context, source, destination string) error
// Size 获取文件大小
Size(ctx context.Context, path string) (int64, error)
// LastModified 获取文件修改时间
LastModified(ctx context.Context, path string) (time.Time, error)
// MimeType 获取文件MIME类型
MimeType(ctx context.Context, path string) (string, error)
// SetVisibility 设置文件可见性
SetVisibility(ctx context.Context, path, visibility string) error
// Visibility 获取文件可见性
Visibility(ctx context.Context, path string) (string, error)
// URL 获取文件URL
URL(ctx context.Context, path string) string
// TemporaryURL 获取临时URL
TemporaryURL(ctx context.Context, path string, expiration time.Duration) (string, error)
// Checksum 计算文件校验和
Checksum(ctx context.Context, path string, algorithm string) (string, error)
}
FileSystem 文件存储系统接口
func ConvertToStorageFileSystem ¶
func ConvertToStorageFileSystem(coreFS core.FileSystem) FileSystem
ConvertToStorageFileSystem 将core.FileSystem转换为storage.FileSystem
type FileSystemAdapter ¶
type FileSystemAdapter struct {
CoreFS core.FileSystem
}
FileSystemAdapter 适配器,用于将core.FileSystem转换为storage.FileSystem
func (*FileSystemAdapter) AllDirectories ¶
func (*FileSystemAdapter) Copy ¶
func (fs *FileSystemAdapter) Copy(ctx context.Context, source, destination string) error
func (*FileSystemAdapter) CreateDirectory ¶
func (fs *FileSystemAdapter) CreateDirectory(ctx context.Context, path string, options ...WriteOption) error
func (*FileSystemAdapter) Delete ¶
func (fs *FileSystemAdapter) Delete(ctx context.Context, path string) error
func (*FileSystemAdapter) DeleteDirectory ¶
func (fs *FileSystemAdapter) DeleteDirectory(ctx context.Context, path string) error
func (*FileSystemAdapter) Directories ¶
func (*FileSystemAdapter) LastModified ¶
func (*FileSystemAdapter) Move ¶
func (fs *FileSystemAdapter) Move(ctx context.Context, source, destination string) error
func (*FileSystemAdapter) SetVisibility ¶
func (fs *FileSystemAdapter) SetVisibility(ctx context.Context, path, visibility string) error
func (*FileSystemAdapter) TemporaryURL ¶
func (*FileSystemAdapter) URL ¶
func (fs *FileSystemAdapter) URL(ctx context.Context, path string) string
func (*FileSystemAdapter) Visibility ¶
func (*FileSystemAdapter) Write ¶
func (fs *FileSystemAdapter) Write(ctx context.Context, path string, content []byte, options ...WriteOption) error
func (*FileSystemAdapter) WriteStream ¶
func (fs *FileSystemAdapter) WriteStream(ctx context.Context, path string, content io.Reader, options ...WriteOption) error
type FileValidator ¶
type FileValidator func(ctx context.Context, file *UploadedFile) error
FileValidator 文件验证器接口
type ImageFormat ¶
type ImageFormat string
ImageFormat 图片格式
const ( JPEG ImageFormat = "jpeg" PNG ImageFormat = "png" GIF ImageFormat = "gif" )
支持的图片格式
type ImageResizeOptions ¶
type ImageResizeOptions struct {
// 目标宽度
Width int
// 目标高度
Height int
// 质量 (1-100,仅对JPEG有效)
Quality int
// 目标格式
Format ImageFormat
// 是否保持比例
KeepAspectRatio bool
// 调整模式:fit, fill, stretch
Mode string
// 填充颜色 (用于填充模式)
FillColor string
// 是否保存原始文件
KeepOriginal bool
// 目标路径
TargetPath string
// 目标磁盘
TargetDisk string
}
ImageResizeOptions 图片缩放选项
func DefaultImageResizeOptions ¶
func DefaultImageResizeOptions() *ImageResizeOptions
DefaultImageResizeOptions 返回默认的图片缩放选项
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 存储管理器
func (*Manager) CreateDirectory ¶
CreateDirectory 在默认磁盘上创建目录
func (*Manager) DefaultDisk ¶
func (m *Manager) DefaultDisk() (FileSystem, error)
DefaultDisk 获取默认文件系统驱动
func (*Manager) DeleteDirectory ¶
DeleteDirectory 从默认磁盘删除目录
func (*Manager) Directories ¶
Directories 列出默认磁盘目录下的所有子目录
func (*Manager) GetDefaultDiskName ¶
GetDefaultDiskName 获取默认文件系统驱动名称
func (*Manager) GetDiskNames ¶
GetDiskNames 获取所有已注册的文件系统驱动名称
func (*Manager) RegisterDisk ¶
RegisterDisk 注册存储驱动
func (*Manager) SetDefaultDisk ¶
SetDefaultDisk 设置默认文件系统驱动
func (*Manager) TemporaryURL ¶
func (m *Manager) TemporaryURL(ctx context.Context, path string, expiration time.Duration) (string, error)
TemporaryURL 获取默认磁盘上文件的临时URL
func (*Manager) UnregisterDisk ¶
UnregisterDisk 注销文件系统驱动
func (*Manager) Write ¶
func (m *Manager) Write(ctx context.Context, path string, content []byte, options ...WriteOption) error
Write 向默认磁盘写入文件
func (*Manager) WriteStream ¶
func (m *Manager) WriteStream(ctx context.Context, path string, content interface{}, options ...WriteOption) error
WriteStream 向默认磁盘通过流写入文件
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache 内存缓存实现
func (*MemoryCache) FlushByPattern ¶
func (c *MemoryCache) FlushByPattern(ctx context.Context, pattern string) error
FlushByPattern 按模式清空缓存
func (*MemoryCache) Forget ¶
func (c *MemoryCache) Forget(ctx context.Context, key string) error
Forget 删除缓存项
type Metadata ¶
type Metadata struct {
// Path 文件路径
Path string `json:"path"`
// Name 文件名
Name string `json:"name"`
// Extension 文件扩展名
Extension string `json:"extension"`
// Size 文件大小(字节)
Size int64 `json:"size"`
// LastModified 最后修改时间
LastModified time.Time `json:"last_modified"`
// MimeType 文件MIME类型
MimeType string `json:"mime_type"`
// Visibility 文件可见性
Visibility string `json:"visibility"`
// Checksum 文件校验和
Checksum string `json:"checksum,omitempty"`
// IsDirectory 是否为目录
IsDirectory bool `json:"is_directory"`
// Custom 自定义元数据
Custom map[string]interface{} `json:"custom,omitempty"`
}
Metadata 文件元数据管理
func (*Metadata) WithChecksum ¶
WithChecksum 设置校验和
func (*Metadata) WithCustom ¶
WithCustom 设置自定义元数据
func (*Metadata) WithIsDirectory ¶
WithIsDirectory 设置是否为目录
func (*Metadata) WithLastModified ¶
WithLastModified 设置最后修改时间
func (*Metadata) WithMimeType ¶
WithMimeType 设置MIME类型
func (*Metadata) WithVisibility ¶
WithVisibility 设置可见性
type MigrationOptions ¶
type MigrationOptions struct {
// 是否递归处理子目录
Recursive bool
// 文件匹配模式(例如 *.jpg)
Pattern string
// 是否保留目录结构
PreserveStructure bool
// 目标目录
TargetDirectory string
// 并发迁移的最大文件数
MaxConcurrent int
// 失败时是否继续
ContinueOnError bool
// 是否覆盖目标文件
Overwrite bool
// 处理进度回调
ProgressCallback func(processed, total int, currentFile string)
}
MigrationOptions 迁移选项
func DefaultMigrationOptions ¶
func DefaultMigrationOptions() *MigrationOptions
DefaultMigrationOptions 返回默认的迁移选项
type MigrationResult ¶
type MigrationResult struct {
// 成功迁移的文件数
SuccessCount int
// 失败的文件数
FailedCount int
// 总处理文件数
TotalCount int
// 失败的文件及错误
Failures map[string]error
// 开始时间
StartTime time.Time
// 结束时间
EndTime time.Time
// 耗时
Duration time.Duration
}
MigrationResult 迁移结果
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator 文件迁移器
func (*Migrator) BatchCopy ¶
func (m *Migrator) BatchCopy(ctx context.Context, disk string, sourceDirectory, targetDirectory string, options *MigrationOptions) (*MigrationResult, error)
BatchCopy 批量复制文件
func (*Migrator) BatchMove ¶
func (m *Migrator) BatchMove(ctx context.Context, disk string, sourceDirectory, targetDirectory string, options *MigrationOptions) (*MigrationResult, error)
BatchMove 批量移动文件
func (*Migrator) Migrate ¶
func (m *Migrator) Migrate(ctx context.Context, sourceDisk, targetDisk string, sourceDirectory string, options *MigrationOptions) (*MigrationResult, error)
Migrate 在两个存储之间迁移文件
func (*Migrator) Sync ¶
func (m *Migrator) Sync(ctx context.Context, sourceDisk, targetDisk string, directory string, options *MigrationOptions) (*MigrationResult, error)
Sync 同步两个存储之间的文件
type ProcessorManager ¶
type ProcessorManager struct {
// contains filtered or unexported fields
}
ProcessorManager 文件处理管理器
func NewProcessorManager ¶
func NewProcessorManager(manager *Manager) *ProcessorManager
NewProcessorManager 创建新的文件处理管理器
func (*ProcessorManager) AddWatermark ¶
func (pm *ProcessorManager) AddWatermark(ctx context.Context, sourcePath string, options *WatermarkOptions) (string, error)
AddWatermark 添加水印
func (*ProcessorManager) BatchProcess ¶
func (pm *ProcessorManager) BatchProcess(ctx context.Context, directory string, options *BatchProcessOptions) (*BatchProcessResult, error)
BatchProcess 批量处理文件
func (*ProcessorManager) ConvertFile ¶
func (pm *ProcessorManager) ConvertFile(ctx context.Context, sourcePath string, options *FileConvertOptions) (string, error)
ConvertFile 转换文件格式
func (*ProcessorManager) ResizeImage ¶
func (pm *ProcessorManager) ResizeImage(ctx context.Context, sourcePath string, options *ImageResizeOptions) (string, error)
ResizeImage 调整图片大小
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider 文件存储系统服务提供者
type StorageConfig ¶
type StorageConfig struct {
// 默认驱动
DefaultDisk string `mapstructure:"default_disk"`
// 磁盘配置
Disks map[string]DiskConfig `mapstructure:"disks"`
}
StorageConfig 文件存储系统配置
type StorageToCoreFSAdapter ¶
type StorageToCoreFSAdapter struct {
StorageFS FileSystem
}
StorageToCoreFSAdapter 适配器,将storage.FileSystem转换为core.FileSystem
func (*StorageToCoreFSAdapter) AllDirectories ¶
func (*StorageToCoreFSAdapter) Copy ¶
func (fs *StorageToCoreFSAdapter) Copy(ctx context.Context, source, destination string) error
func (*StorageToCoreFSAdapter) CreateDirectory ¶
func (fs *StorageToCoreFSAdapter) CreateDirectory(ctx context.Context, path string, options ...core.WriteOption) error
func (*StorageToCoreFSAdapter) Delete ¶
func (fs *StorageToCoreFSAdapter) Delete(ctx context.Context, path string) error
func (*StorageToCoreFSAdapter) DeleteDirectory ¶
func (fs *StorageToCoreFSAdapter) DeleteDirectory(ctx context.Context, path string) error
func (*StorageToCoreFSAdapter) Directories ¶
func (*StorageToCoreFSAdapter) LastModified ¶
func (*StorageToCoreFSAdapter) Move ¶
func (fs *StorageToCoreFSAdapter) Move(ctx context.Context, source, destination string) error
func (*StorageToCoreFSAdapter) SetVisibility ¶
func (fs *StorageToCoreFSAdapter) SetVisibility(ctx context.Context, path, visibility string) error
func (*StorageToCoreFSAdapter) TemporaryURL ¶
func (*StorageToCoreFSAdapter) URL ¶
func (fs *StorageToCoreFSAdapter) URL(ctx context.Context, path string) string
func (*StorageToCoreFSAdapter) Visibility ¶
func (*StorageToCoreFSAdapter) Write ¶
func (fs *StorageToCoreFSAdapter) Write(ctx context.Context, path string, content []byte, options ...core.WriteOption) error
func (*StorageToCoreFSAdapter) WriteStream ¶
func (fs *StorageToCoreFSAdapter) WriteStream(ctx context.Context, path string, content io.Reader, options ...core.WriteOption) error
type StorageToCoreFSFileAdapter ¶
type StorageToCoreFSFileAdapter struct {
StorageFile File
}
StorageToCoreFSFileAdapter 适配器,将storage.File转换为core.File
func (*StorageToCoreFSFileAdapter) Extension ¶
func (f *StorageToCoreFSFileAdapter) Extension() string
func (*StorageToCoreFSFileAdapter) IsDirectory ¶
func (f *StorageToCoreFSFileAdapter) IsDirectory() bool
func (*StorageToCoreFSFileAdapter) LastModified ¶
func (f *StorageToCoreFSFileAdapter) LastModified() time.Time
func (*StorageToCoreFSFileAdapter) Metadata ¶
func (f *StorageToCoreFSFileAdapter) Metadata() map[string]interface{}
func (*StorageToCoreFSFileAdapter) MimeType ¶
func (f *StorageToCoreFSFileAdapter) MimeType() string
func (*StorageToCoreFSFileAdapter) Name ¶
func (f *StorageToCoreFSFileAdapter) Name() string
func (*StorageToCoreFSFileAdapter) Path ¶
func (f *StorageToCoreFSFileAdapter) Path() string
实现core.File接口
func (*StorageToCoreFSFileAdapter) Read ¶
func (f *StorageToCoreFSFileAdapter) Read(ctx context.Context) ([]byte, error)
func (*StorageToCoreFSFileAdapter) ReadStream ¶
func (f *StorageToCoreFSFileAdapter) ReadStream(ctx context.Context) (io.ReadCloser, error)
func (*StorageToCoreFSFileAdapter) Size ¶
func (f *StorageToCoreFSFileAdapter) Size() int64
func (*StorageToCoreFSFileAdapter) TemporaryURL ¶
func (*StorageToCoreFSFileAdapter) URL ¶
func (f *StorageToCoreFSFileAdapter) URL() string
func (*StorageToCoreFSFileAdapter) Visibility ¶
func (f *StorageToCoreFSFileAdapter) Visibility() string
type UploadedFile ¶
type UploadedFile struct {
// Filename 原始文件名
Filename string
// SavedAs 保存后的文件名
SavedAs string
// Size 文件大小
Size int64
// MimeType MIME类型
MimeType string
// Extension 文件扩展名
Extension string
// Content 文件内容
Content []byte
// Stream 文件数据流
Stream io.Reader
// Path 保存路径
Path string
// URL 文件URL
URL string
// Metadata 文件元数据
Metadata *Metadata
}
UploadedFile 上传的文件信息
type Uploader ¶
type Uploader struct {
// contains filtered or unexported fields
}
Uploader 文件上传助手
func (*Uploader) AfterUpload ¶
func (u *Uploader) AfterUpload(callback AfterUploadFunc) *Uploader
AfterUpload 添加上传后回调函数
func (*Uploader) AllowMimeTypes ¶
AllowMimeTypes 设置允许的MIME类型
func (*Uploader) AllowOverwrite ¶
AllowOverwrite 设置是否允许覆盖同名文件
func (*Uploader) BeforeUpload ¶
func (u *Uploader) BeforeUpload(callback BeforeUploadFunc) *Uploader
BeforeUpload 添加上传前回调函数
func (*Uploader) GenerateUniqueName ¶
GenerateUniqueName 设置是否生成唯一文件名
func (*Uploader) InDirectory ¶
InDirectory 设置上传目录
func (*Uploader) MaxFileSize ¶
MaxFileSize 设置最大文件大小
func (*Uploader) UploadFile ¶
func (u *Uploader) UploadFile(ctx context.Context, content []byte, filename string) (*UploadedFile, error)
UploadFile 上传文件内容
func (*Uploader) UploadFromMultipartFile ¶
func (u *Uploader) UploadFromMultipartFile(ctx context.Context, file multipart.File, header *multipart.FileHeader) (*UploadedFile, error)
UploadFromMultipartFile 从multipart.File上传文件
func (*Uploader) UploadFromRequest ¶
func (u *Uploader) UploadFromRequest(ctx context.Context, r *http.Request, fieldName string) (*UploadedFile, error)
UploadFromRequest 从HTTP请求中上传文件
func (*Uploader) UploadMultiple ¶
func (u *Uploader) UploadMultiple(ctx context.Context, files map[string][]byte) ([]*UploadedFile, error)
UploadMultiple 上传多个文件
func (*Uploader) WithCustomNamer ¶
WithCustomNamer 设置自定义文件命名函数
func (*Uploader) WithValidator ¶
func (u *Uploader) WithValidator(validator FileValidator) *Uploader
WithValidator 添加文件验证器
func (*Uploader) WithVisibility ¶
WithVisibility 设置文件可见性
type WatermarkOptions ¶
type WatermarkOptions struct {
// 水印图片路径
WatermarkPath string
// 水印位置: top-left, top-right, bottom-left, bottom-right, center
Position string
// 水印透明度 (0-100)
Opacity int
// 水印边距
Margin int
// 是否保存原始文件
KeepOriginal bool
// 目标路径
TargetPath string
// 目标磁盘
TargetDisk string
}
WatermarkOptions 水印选项
func DefaultWatermarkOptions ¶
func DefaultWatermarkOptions() *WatermarkOptions
DefaultWatermarkOptions 返回默认的水印选项
type WriteOption ¶
type WriteOption func(*WriteOptions)
WriteOption 写入文件的选项
func ConvertToStorageWriteOptions ¶
func ConvertToStorageWriteOptions(options []core.WriteOption) []WriteOption
ConvertToStorageWriteOptions 将core.WriteOption转换为storage.WriteOption
func WithMetadata ¶
func WithMetadata(metadata map[string]interface{}) WriteOption
WithMetadata 设置文件元数据选项
func WithPermissions ¶
func WithPermissions(permissions os.FileMode) WriteOption
WithPermissions 设置文件权限选项