Documentation
¶
Overview ¶
Package storage 提供文件存储的抽象层和不同存储策略的实现
Index ¶
- Constants
- func CalculateFileHash(file *multipart.FileHeader) (string, error)
- func GenerateFileInfo(fileName string, uploadID string) (path, suffix, prefix, uuidFileName string)
- func GenerateFilePath(fileName string, uploadID string, pathManager *PathManager) (path, suffix, prefix, uuidFileName, savePath string)
- func ParseExpireInfo(expireValue int, expireStyle string) (expiredAt *int64, expiredCount int, usedCount int)
- func ValidateFileSize(file *multipart.FileHeader, maxSize int64) error
- type ChunkOperationResult
- type ConcreteStorageService
- func (css *ConcreteStorageService) CleanChunksWithResult(uploadID string) *FileOperationResult
- func (css *ConcreteStorageService) DeleteFileWithResult(fileCode *models.FileCode) *FileOperationResult
- func (css *ConcreteStorageService) FileExists(fileCode *models.FileCode) bool
- func (css *ConcreteStorageService) GenerateFileInfo(fileName string, uploadID string) *FileGenerationInfo
- func (css *ConcreteStorageService) GetAvailableStorageTypes() []string
- func (css *ConcreteStorageService) GetCurrentStorageType() string
- func (css *ConcreteStorageService) GetFileDownloadInfo(fileCode *models.FileCode) (*FileDownloadInfo, error)
- func (css *ConcreteStorageService) GetFileResponse(c *gin.Context, fileCode *models.FileCode) error
- func (css *ConcreteStorageService) MergeChunksWithResult(uploadID string, chunk *models.UploadChunk, savePath string) *FileOperationResult
- func (css *ConcreteStorageService) SaveChunkWithResult(uploadID string, chunkIndex int, data []byte, chunkHash string) *ChunkOperationResult
- func (css *ConcreteStorageService) SaveFileWithResult(file *multipart.FileHeader, savePath string) *FileOperationResult
- func (css *ConcreteStorageService) SwitchStorageType(storageType string) error
- func (css *ConcreteStorageService) TestConnectionWithResult() *StorageInfo
- type FileDownloadInfo
- type FileGenerationInfo
- type FileOperationResult
- type LocalStorageStrategy
- func (ls *LocalStorageStrategy) DeleteFile(path string) error
- func (ls *LocalStorageStrategy) FileExists(path string) bool
- func (ls *LocalStorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
- func (ls *LocalStorageStrategy) ReadFile(path string) ([]byte, error)
- func (ls *LocalStorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
- func (ls *LocalStorageStrategy) ServeFile(c *gin.Context, filePath string, fileName string) error
- func (ls *LocalStorageStrategy) TestConnection() error
- func (ls *LocalStorageStrategy) WriteFile(path string, data []byte) error
- type NFSStorageStrategy
- func (nfs *NFSStorageStrategy) Cleanup() error
- func (nfs *NFSStorageStrategy) DeleteFile(path string) error
- func (nfs *NFSStorageStrategy) FileExists(path string) bool
- func (nfs *NFSStorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
- func (nfs *NFSStorageStrategy) GetMountInfo() map[string]interface{}
- func (nfs *NFSStorageStrategy) ReadFile(path string) ([]byte, error)
- func (nfs *NFSStorageStrategy) Remount() error
- func (nfs *NFSStorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
- func (nfs *NFSStorageStrategy) ServeFile(c *gin.Context, filePath string, fileName string) error
- func (nfs *NFSStorageStrategy) TestConnection() error
- func (nfs *NFSStorageStrategy) WriteFile(path string, data []byte) error
- type PathManager
- func (pm *PathManager) CleanPath(path string) string
- func (pm *PathManager) GetChunkBasePath() string
- func (pm *PathManager) GetChunkDir(uploadID string) string
- func (pm *PathManager) GetChunkPath(uploadID string, chunkIndex int) string
- func (pm *PathManager) GetDateBasedPath(filename string) string
- func (pm *PathManager) GetFullPath(relativePath string) string
- type S3StorageStrategy
- func (ss *S3StorageStrategy) DeleteFile(path string) error
- func (ss *S3StorageStrategy) FileExists(path string) bool
- func (ss *S3StorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
- func (ss *S3StorageStrategy) ReadFile(path string) ([]byte, error)
- func (ss *S3StorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
- func (ss *S3StorageStrategy) ServeFile(c *gin.Context, filePath string, fileName string) error
- func (ss *S3StorageStrategy) TestConnection() error
- func (ss *S3StorageStrategy) WriteFile(path string, data []byte) error
- type StorageInfo
- type StorageInterface
- type StorageManager
- func (sm *StorageManager) GetAvailableStorages() []string
- func (sm *StorageManager) GetCurrentStorage() string
- func (sm *StorageManager) GetStorage() StorageInterface
- func (sm *StorageManager) GetStorageInstance(storageType string) (StorageInterface, bool)
- func (sm *StorageManager) ReconfigureNFS(server, nfsPath, mountPoint, version, options string, timeout int, ...) error
- func (sm *StorageManager) ReconfigureWebDAV(hostname, username, password, rootPath string) error
- func (sm *StorageManager) SwitchStorage(storageType string) error
- func (sm *StorageManager) TestStorage(storageType string) error
- type StorageOperations
- type StorageOperator
- func (so *StorageOperator) CleanChunks(uploadID string) error
- func (so *StorageOperator) DeleteFile(fileCode *models.FileCode) error
- func (so *StorageOperator) GetFileResponse(c *gin.Context, fileCode *models.FileCode) error
- func (so *StorageOperator) GetFileURL(fileCode *models.FileCode) (string, error)
- func (so *StorageOperator) MergeChunks(uploadID string, chunk *models.UploadChunk, savePath string) error
- func (so *StorageOperator) SaveChunk(uploadID string, chunkIndex int, data []byte, chunkHash string) error
- func (so *StorageOperator) SaveFile(file *multipart.FileHeader, savePath string) error
- type StorageStrategy
- type StrategyBasedStorage
- func (sbs *StrategyBasedStorage) CleanChunks(uploadID string) error
- func (sbs *StrategyBasedStorage) DeleteFile(fileCode *models.FileCode) error
- func (sbs *StrategyBasedStorage) GetFileResponse(c *gin.Context, fileCode *models.FileCode) error
- func (sbs *StrategyBasedStorage) GetFileURL(fileCode *models.FileCode) (string, error)
- func (sbs *StrategyBasedStorage) MergeChunks(uploadID string, chunk *models.UploadChunk, savePath string) error
- func (sbs *StrategyBasedStorage) SaveChunk(uploadID string, chunkIndex int, data []byte, chunkHash string) error
- func (sbs *StrategyBasedStorage) SaveFile(file *multipart.FileHeader, savePath string) error
- func (sbs *StrategyBasedStorage) TestConnection() error
- type WebDAVStorageStrategy
- func (ws *WebDAVStorageStrategy) DeleteFile(path string) error
- func (ws *WebDAVStorageStrategy) FileExists(path string) bool
- func (ws *WebDAVStorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
- func (ws *WebDAVStorageStrategy) ReadFile(path string) ([]byte, error)
- func (ws *WebDAVStorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
- func (ws *WebDAVStorageStrategy) ServeFile(c *gin.Context, filePath string, fileName string) error
- func (ws *WebDAVStorageStrategy) TestConnection() error
- func (ws *WebDAVStorageStrategy) WriteFile(path string, data []byte) error
Constants ¶
const (
ShareDownloadPath = "/share/download"
)
Variables ¶
This section is empty.
Functions ¶
func CalculateFileHash ¶
func CalculateFileHash(file *multipart.FileHeader) (string, error)
func GenerateFileInfo ¶
GenerateFileInfo 生成文件信息 (不依赖PathManager)
func GenerateFilePath ¶
func GenerateFilePath(fileName string, uploadID string, pathManager *PathManager) (path, suffix, prefix, uuidFileName, savePath string)
GenerateFilePath 生成文件路径 (兼容旧代码)
func ParseExpireInfo ¶
func ValidateFileSize ¶
func ValidateFileSize(file *multipart.FileHeader, maxSize int64) error
Types ¶
type ChunkOperationResult ¶
type ChunkOperationResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error error `json:"-"`
UploadID string `json:"upload_id"`
ChunkIndex int `json:"chunk_index,omitempty"`
ChunkHash string `json:"chunk_hash,omitempty"`
ChunkSize int `json:"chunk_size,omitempty"`
TotalChunks int `json:"total_chunks,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
ChunkOperationResult 分片操作结果
type ConcreteStorageService ¶
type ConcreteStorageService struct {
// contains filtered or unexported fields
}
ConcreteStorageService 具体的存储服务实现
func NewConcreteStorageService ¶
func NewConcreteStorageService(manager *config.ConfigManager) *ConcreteStorageService
NewConcreteStorageService 创建具体的存储服务
func (*ConcreteStorageService) CleanChunksWithResult ¶
func (css *ConcreteStorageService) CleanChunksWithResult(uploadID string) *FileOperationResult
CleanChunksWithResult 清理分片并返回结果
func (*ConcreteStorageService) DeleteFileWithResult ¶
func (css *ConcreteStorageService) DeleteFileWithResult(fileCode *models.FileCode) *FileOperationResult
DeleteFileWithResult 删除文件并返回结果
func (*ConcreteStorageService) FileExists ¶ added in v1.9.5
func (css *ConcreteStorageService) FileExists(fileCode *models.FileCode) bool
FileExists 检查文件是否存在
func (*ConcreteStorageService) GenerateFileInfo ¶
func (css *ConcreteStorageService) GenerateFileInfo(fileName string, uploadID string) *FileGenerationInfo
GenerateFileInfo 生成文件信息
func (*ConcreteStorageService) GetAvailableStorageTypes ¶
func (css *ConcreteStorageService) GetAvailableStorageTypes() []string
GetAvailableStorageTypes 获取可用的存储类型
func (*ConcreteStorageService) GetCurrentStorageType ¶
func (css *ConcreteStorageService) GetCurrentStorageType() string
GetCurrentStorageType 获取当前存储类型
func (*ConcreteStorageService) GetFileDownloadInfo ¶
func (css *ConcreteStorageService) GetFileDownloadInfo(fileCode *models.FileCode) (*FileDownloadInfo, error)
GetFileDownloadInfo 获取文件下载信息
func (*ConcreteStorageService) GetFileResponse ¶
GetFileResponse 兼容旧接口
func (*ConcreteStorageService) MergeChunksWithResult ¶
func (css *ConcreteStorageService) MergeChunksWithResult(uploadID string, chunk *models.UploadChunk, savePath string) *FileOperationResult
MergeChunksWithResult 合并分片并返回结果
func (*ConcreteStorageService) SaveChunkWithResult ¶
func (css *ConcreteStorageService) SaveChunkWithResult(uploadID string, chunkIndex int, data []byte, chunkHash string) *ChunkOperationResult
SaveChunkWithResult 保存分片并返回结果
func (*ConcreteStorageService) SaveFileWithResult ¶
func (css *ConcreteStorageService) SaveFileWithResult(file *multipart.FileHeader, savePath string) *FileOperationResult
SaveFileWithResult 保存文件并返回结果
func (*ConcreteStorageService) SwitchStorageType ¶
func (css *ConcreteStorageService) SwitchStorageType(storageType string) error
SwitchStorageType 切换存储类型
func (*ConcreteStorageService) TestConnectionWithResult ¶
func (css *ConcreteStorageService) TestConnectionWithResult() *StorageInfo
TestConnectionWithResult 测试连接并返回结果
type FileDownloadInfo ¶
type FileDownloadInfo struct {
FilePath string `json:"file_path"`
FileName string `json:"file_name"`
FileSize int64 `json:"file_size"`
ContentType string `json:"content_type"`
DownloadURL string `json:"download_url,omitempty"`
DirectAccess bool `json:"direct_access"` // 是否支持直接访问
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
FileDownloadInfo 文件下载信息
type FileGenerationInfo ¶
type FileGenerationInfo struct {
Path string `json:"path"` // 相对路径(如: 2024/01/15)
Suffix string `json:"suffix"` // 文件扩展名
Prefix string `json:"prefix"` // 原始文件名(不含扩展名)
UUIDFileName string `json:"uuid_filename"` // 生成的唯一文件名
SavePath string `json:"save_path"` // 完整保存路径
FullPath string `json:"full_path"` // 绝对路径
}
FileGenerationInfo 文件生成信息
type FileOperationResult ¶
type FileOperationResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error error `json:"-"`
FilePath string `json:"file_path,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
FileHash string `json:"file_hash,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
FileOperationResult 文件操作结果
type LocalStorageStrategy ¶
type LocalStorageStrategy struct {
// contains filtered or unexported fields
}
LocalStorageStrategy 本地存储策略实现
func NewLocalStorageStrategy ¶
func NewLocalStorageStrategy(basePath string) *LocalStorageStrategy
NewLocalStorageStrategy 创建本地存储策略
func (*LocalStorageStrategy) DeleteFile ¶
func (ls *LocalStorageStrategy) DeleteFile(path string) error
DeleteFile 删除文件
func (*LocalStorageStrategy) FileExists ¶
func (ls *LocalStorageStrategy) FileExists(path string) bool
FileExists 检查文件是否存在
func (*LocalStorageStrategy) GenerateFileURL ¶
func (ls *LocalStorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
GenerateFileURL 生成文件URL
func (*LocalStorageStrategy) ReadFile ¶
func (ls *LocalStorageStrategy) ReadFile(path string) ([]byte, error)
ReadFile 读取文件
func (*LocalStorageStrategy) SaveUploadFile ¶
func (ls *LocalStorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
SaveUploadFile 保存上传的文件
func (*LocalStorageStrategy) TestConnection ¶
func (ls *LocalStorageStrategy) TestConnection() error
TestConnection 测试本地存储连接
type NFSStorageStrategy ¶
type NFSStorageStrategy struct {
// contains filtered or unexported fields
}
NFSStorageStrategy NFS存储策略实现
func NewNFSStorageStrategy ¶
func NewNFSStorageStrategy(server, nfsPath, mountPoint, version, options string, timeout int, autoMount bool, retryCount int, subPath string) (*NFSStorageStrategy, error)
NewNFSStorageStrategy 创建NFS存储策略
func (*NFSStorageStrategy) DeleteFile ¶
func (nfs *NFSStorageStrategy) DeleteFile(path string) error
DeleteFile 删除文件
func (*NFSStorageStrategy) FileExists ¶
func (nfs *NFSStorageStrategy) FileExists(path string) bool
FileExists 检查文件是否存在
func (*NFSStorageStrategy) GenerateFileURL ¶
func (nfs *NFSStorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
GenerateFileURL 生成文件URL
func (*NFSStorageStrategy) GetMountInfo ¶
func (nfs *NFSStorageStrategy) GetMountInfo() map[string]interface{}
GetMountInfo 获取挂载信息
func (*NFSStorageStrategy) ReadFile ¶
func (nfs *NFSStorageStrategy) ReadFile(path string) ([]byte, error)
ReadFile 读取文件
func (*NFSStorageStrategy) SaveUploadFile ¶
func (nfs *NFSStorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
SaveUploadFile 保存上传的文件
func (*NFSStorageStrategy) TestConnection ¶
func (nfs *NFSStorageStrategy) TestConnection() error
TestConnection 测试NFS连接
type PathManager ¶
type PathManager struct {
// contains filtered or unexported fields
}
PathManager 路径管理器,用于统一处理各种存储后端的路径
func (*PathManager) CleanPath ¶
func (pm *PathManager) CleanPath(path string) string
CleanPath 清理路径,确保路径格式正确
func (*PathManager) GetChunkBasePath ¶
func (pm *PathManager) GetChunkBasePath() string
GetChunkBasePath 获取分片存储的基础路径
func (*PathManager) GetChunkDir ¶
func (pm *PathManager) GetChunkDir(uploadID string) string
GetChunkDir 获取特定上传ID的分片目录
func (*PathManager) GetChunkPath ¶
func (pm *PathManager) GetChunkPath(uploadID string, chunkIndex int) string
GetChunkPath 获取特定分片的完整路径
func (*PathManager) GetDateBasedPath ¶
func (pm *PathManager) GetDateBasedPath(filename string) string
GetDateBasedPath 获取基于日期的文件路径
func (*PathManager) GetFullPath ¶
func (pm *PathManager) GetFullPath(relativePath string) string
GetFullPath 获取基于基础路径的完整路径
type S3StorageStrategy ¶
type S3StorageStrategy struct {
// contains filtered or unexported fields
}
S3StorageStrategy S3 存储策略实现
func NewS3StorageStrategy ¶
func NewS3StorageStrategy(accessKeyID, secretAccessKey, bucketName, endpointURL, regionName, sessionToken, hostname string, proxy bool, basePath string) (*S3StorageStrategy, error)
NewS3StorageStrategy 创建 S3 存储策略
func (*S3StorageStrategy) DeleteFile ¶
func (ss *S3StorageStrategy) DeleteFile(path string) error
DeleteFile 删除文件(对于目录,删除所有匹配前缀的对象)
func (*S3StorageStrategy) FileExists ¶
func (ss *S3StorageStrategy) FileExists(path string) bool
FileExists 检查文件是否存在
func (*S3StorageStrategy) GenerateFileURL ¶
func (ss *S3StorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
GenerateFileURL 生成文件URL
func (*S3StorageStrategy) ReadFile ¶
func (ss *S3StorageStrategy) ReadFile(path string) ([]byte, error)
ReadFile 读取文件
func (*S3StorageStrategy) SaveUploadFile ¶
func (ss *S3StorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
SaveUploadFile 保存上传的文件
func (*S3StorageStrategy) TestConnection ¶
func (ss *S3StorageStrategy) TestConnection() error
TestConnection 测试 S3 连接
type StorageInfo ¶
type StorageInfo struct {
Type string `json:"type"`
Available bool `json:"available"`
Connected bool `json:"connected"`
TotalSpace int64 `json:"total_space,omitempty"`
UsedSpace int64 `json:"used_space,omitempty"`
FreeSpace int64 `json:"free_space,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
LastChecked time.Time `json:"last_checked"`
}
StorageInfo 存储信息
type StorageInterface ¶
type StorageInterface interface {
SaveFile(file *multipart.FileHeader, savePath string) error
SaveChunk(uploadID string, chunkIndex int, data []byte, chunkHash string) error
MergeChunks(uploadID string, chunk *models.UploadChunk, savePath string) error
CleanChunks(uploadID string) error
GetFileResponse(c *gin.Context, fileCode *models.FileCode) error
GetFileURL(fileCode *models.FileCode) (string, error)
DeleteFile(fileCode *models.FileCode) error
}
StorageInterface 存储接口
type StorageManager ¶
type StorageManager struct {
// contains filtered or unexported fields
}
StorageManager 存储管理器
func NewStorageManager ¶
func NewStorageManager(manager *config.ConfigManager) *StorageManager
func (*StorageManager) GetAvailableStorages ¶
func (sm *StorageManager) GetAvailableStorages() []string
GetAvailableStorages 获取可用的存储类型
func (*StorageManager) GetCurrentStorage ¶
func (sm *StorageManager) GetCurrentStorage() string
GetCurrentStorage 获取当前存储类型
func (*StorageManager) GetStorage ¶
func (sm *StorageManager) GetStorage() StorageInterface
func (*StorageManager) GetStorageInstance ¶
func (sm *StorageManager) GetStorageInstance(storageType string) (StorageInterface, bool)
GetStorageInstance 获取指定类型的存储实例
func (*StorageManager) ReconfigureNFS ¶
func (sm *StorageManager) ReconfigureNFS(server, nfsPath, mountPoint, version, options string, timeout int, autoMount bool, retryCount int, subPath string) error
ReconfigureNFS 重新配置 NFS 存储
func (*StorageManager) ReconfigureWebDAV ¶
func (sm *StorageManager) ReconfigureWebDAV(hostname, username, password, rootPath string) error
ReconfigureWebDAV 重新配置 WebDAV 存储
func (*StorageManager) SwitchStorage ¶
func (sm *StorageManager) SwitchStorage(storageType string) error
SwitchStorage 切换存储后端
func (*StorageManager) TestStorage ¶
func (sm *StorageManager) TestStorage(storageType string) error
TestStorage 测试存储连接
type StorageOperations ¶
type StorageOperations interface {
// 文件操作
SaveFileWithResult(file *multipart.FileHeader, savePath string) *FileOperationResult
DeleteFileWithResult(fileCode *models.FileCode) *FileOperationResult
GetFileDownloadInfo(fileCode *models.FileCode) (*FileDownloadInfo, error)
// 分片操作
SaveChunkWithResult(uploadID string, chunkIndex int, data []byte, chunkHash string) *ChunkOperationResult
MergeChunksWithResult(uploadID string, chunk *models.UploadChunk, savePath string) *FileOperationResult
CleanChunksWithResult(uploadID string) *FileOperationResult
// 连接测试
TestConnectionWithResult() *StorageInfo
// 传统兼容方法(逐步废弃)
GetFileResponse(c *gin.Context, fileCode *models.FileCode) error
}
StorageOperations 存储操作接口(保留必要的interface,但简化)
type StorageOperator ¶
type StorageOperator struct {
// contains filtered or unexported fields
}
StorageOperator 通用存储操作器 - 包含公共逻辑
func NewStorageOperator ¶
func NewStorageOperator(strategy StorageStrategy, pathManager *PathManager) *StorageOperator
NewStorageOperator 创建存储操作器
func (*StorageOperator) CleanChunks ¶
func (so *StorageOperator) CleanChunks(uploadID string) error
CleanChunks 清理分片 - 公共逻辑
func (*StorageOperator) DeleteFile ¶
func (so *StorageOperator) DeleteFile(fileCode *models.FileCode) error
DeleteFile 删除文件 - 公共逻辑
func (*StorageOperator) GetFileResponse ¶
GetFileResponse 获取文件响应 - 公共逻辑
func (*StorageOperator) GetFileURL ¶
func (so *StorageOperator) GetFileURL(fileCode *models.FileCode) (string, error)
GetFileURL 获取文件URL - 公共逻辑
func (*StorageOperator) MergeChunks ¶
func (so *StorageOperator) MergeChunks(uploadID string, chunk *models.UploadChunk, savePath string) error
MergeChunks 合并分片 - 公共逻辑
func (*StorageOperator) SaveChunk ¶
func (so *StorageOperator) SaveChunk(uploadID string, chunkIndex int, data []byte, chunkHash string) error
SaveChunk 保存分片 - 公共逻辑
func (*StorageOperator) SaveFile ¶
func (so *StorageOperator) SaveFile(file *multipart.FileHeader, savePath string) error
SaveFile 保存文件 - 公共逻辑
type StorageStrategy ¶
type StorageStrategy interface {
// 基础文件操作
WriteFile(path string, data []byte) error
ReadFile(path string) ([]byte, error)
DeleteFile(path string) error
FileExists(path string) bool
// 上传文件操作
SaveUploadFile(file *multipart.FileHeader, savePath string) error
// 下载操作
ServeFile(c *gin.Context, filePath string, fileName string) error
GenerateFileURL(filePath string, fileName string) (string, error)
// 连接测试
TestConnection() error
}
StorageStrategy 存储策略接口 - 定义每个存储后端的差异化操作
type StrategyBasedStorage ¶
type StrategyBasedStorage struct {
// contains filtered or unexported fields
}
StrategyBasedStorage 基于策略的存储适配器
func NewStrategyBasedStorage ¶
func NewStrategyBasedStorage(strategy StorageStrategy, pathManager *PathManager) *StrategyBasedStorage
NewStrategyBasedStorage 创建基于策略的存储
func (*StrategyBasedStorage) CleanChunks ¶
func (sbs *StrategyBasedStorage) CleanChunks(uploadID string) error
CleanChunks 实现 StorageInterface
func (*StrategyBasedStorage) DeleteFile ¶
func (sbs *StrategyBasedStorage) DeleteFile(fileCode *models.FileCode) error
DeleteFile 实现 StorageInterface
func (*StrategyBasedStorage) GetFileResponse ¶
GetFileResponse 实现 StorageInterface
func (*StrategyBasedStorage) GetFileURL ¶
func (sbs *StrategyBasedStorage) GetFileURL(fileCode *models.FileCode) (string, error)
GetFileURL 实现 StorageInterface
func (*StrategyBasedStorage) MergeChunks ¶
func (sbs *StrategyBasedStorage) MergeChunks(uploadID string, chunk *models.UploadChunk, savePath string) error
MergeChunks 实现 StorageInterface
func (*StrategyBasedStorage) SaveChunk ¶
func (sbs *StrategyBasedStorage) SaveChunk(uploadID string, chunkIndex int, data []byte, chunkHash string) error
SaveChunk 实现 StorageInterface
func (*StrategyBasedStorage) SaveFile ¶
func (sbs *StrategyBasedStorage) SaveFile(file *multipart.FileHeader, savePath string) error
SaveFile 实现 StorageInterface
func (*StrategyBasedStorage) TestConnection ¶
func (sbs *StrategyBasedStorage) TestConnection() error
TestConnection 测试连接
type WebDAVStorageStrategy ¶
type WebDAVStorageStrategy struct {
// contains filtered or unexported fields
}
WebDAVStorageStrategy WebDAV 存储策略实现
func NewWebDAVStorageStrategy ¶
func NewWebDAVStorageStrategy(hostname, username, password, rootPath string) (*WebDAVStorageStrategy, error)
NewWebDAVStorageStrategy 创建 WebDAV 存储策略
func (*WebDAVStorageStrategy) DeleteFile ¶
func (ws *WebDAVStorageStrategy) DeleteFile(path string) error
DeleteFile 删除文件或目录
func (*WebDAVStorageStrategy) FileExists ¶
func (ws *WebDAVStorageStrategy) FileExists(path string) bool
FileExists 检查文件是否存在
func (*WebDAVStorageStrategy) GenerateFileURL ¶
func (ws *WebDAVStorageStrategy) GenerateFileURL(filePath string, fileName string) (string, error)
GenerateFileURL 生成文件URL
func (*WebDAVStorageStrategy) ReadFile ¶
func (ws *WebDAVStorageStrategy) ReadFile(path string) ([]byte, error)
ReadFile 读取文件
func (*WebDAVStorageStrategy) SaveUploadFile ¶
func (ws *WebDAVStorageStrategy) SaveUploadFile(file *multipart.FileHeader, savePath string) error
SaveUploadFile 保存上传的文件
func (*WebDAVStorageStrategy) TestConnection ¶
func (ws *WebDAVStorageStrategy) TestConnection() error
TestConnection 测试 WebDAV 连接