Documentation
¶
Index ¶
- func MimeType(path string) string
- type COSConfig
- type COSStorage
- func (c *COSStorage) Copy(ctx context.Context, srcPath, dstPath string) error
- func (c *COSStorage) Delete(ctx context.Context, path string) error
- func (c *COSStorage) Exists(ctx context.Context, path string) (bool, error)
- func (c *COSStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (c *COSStorage) List(ctx context.Context, prefix string) ([]*FileInfo, error)
- func (c *COSStorage) Move(ctx context.Context, srcPath, dstPath string) error
- func (c *COSStorage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
- func (c *COSStorage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
- func (c *COSStorage) Size(ctx context.Context, path string) (int64, error)
- func (c *COSStorage) URL(ctx context.Context, path string) (string, error)
- type CacheConfig
- type FileHandle
- type FileInfo
- type ImageConfig
- type LocalConfig
- type LocalStorage
- func (ls *LocalStorage) Copy(ctx context.Context, srcPath, dstPath string) error
- func (ls *LocalStorage) Delete(ctx context.Context, path string) error
- func (ls *LocalStorage) Exists(ctx context.Context, path string) (bool, error)
- func (ls *LocalStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (ls *LocalStorage) List(ctx context.Context, prefix string) ([]*FileInfo, error)
- func (ls *LocalStorage) Move(ctx context.Context, srcPath, dstPath string) error
- func (ls *LocalStorage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
- func (ls *LocalStorage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
- func (ls *LocalStorage) Size(ctx context.Context, path string) (int64, error)
- func (ls *LocalStorage) URL(ctx context.Context, path string) (string, error)
- type LoggingConfig
- type MinIOConfig
- type MinIOStorage
- func (m *MinIOStorage) Copy(ctx context.Context, srcPath, dstPath string) error
- func (m *MinIOStorage) Delete(ctx context.Context, path string) error
- func (m *MinIOStorage) Exists(ctx context.Context, path string) (bool, error)
- func (m *MinIOStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (m *MinIOStorage) List(ctx context.Context, prefix string) ([]*FileInfo, error)
- func (m *MinIOStorage) Move(ctx context.Context, srcPath, dstPath string) error
- func (m *MinIOStorage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
- func (m *MinIOStorage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
- func (m *MinIOStorage) Size(ctx context.Context, path string) (int64, error)
- func (m *MinIOStorage) URL(ctx context.Context, path string) (string, error)
- type MonitoringConfig
- type OSSConfig
- type Options
- type QiniuConfig
- type QiniuStorage
- func (q *QiniuStorage) Copy(ctx context.Context, srcPath, dstPath string) error
- func (q *QiniuStorage) Delete(ctx context.Context, path string) error
- func (q *QiniuStorage) Exists(ctx context.Context, path string) (bool, error)
- func (q *QiniuStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (q *QiniuStorage) List(ctx context.Context, prefix string) ([]*FileInfo, error)
- func (q *QiniuStorage) Move(ctx context.Context, srcPath, dstPath string) error
- func (q *QiniuStorage) Put(ctx context.Context, path string, reader io.Reader, _ int64) (*FileInfo, error)
- func (q *QiniuStorage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
- func (q *QiniuStorage) Size(ctx context.Context, path string) (int64, error)
- func (q *QiniuStorage) URL(ctx context.Context, path string) (string, error)
- type S3Config
- type S3Storage
- func (s *S3Storage) Copy(ctx context.Context, srcPath, dstPath string) error
- func (s *S3Storage) Delete(ctx context.Context, path string) error
- func (s *S3Storage) Exists(ctx context.Context, path string) (bool, error)
- func (s *S3Storage) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (s *S3Storage) List(ctx context.Context, prefix string) ([]*FileInfo, error)
- func (s *S3Storage) Move(ctx context.Context, srcPath, dstPath string) error
- func (s *S3Storage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
- func (s *S3Storage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
- func (s *S3Storage) Size(ctx context.Context, path string) (int64, error)
- func (s *S3Storage) URL(ctx context.Context, path string) (string, error)
- type SecurityConfig
- type Storage
- type StorageManager
- func (sm *StorageManager) AddDriver(name string, driver Storage)
- func (sm *StorageManager) Default() (Storage, error)
- func (sm *StorageManager) Delete(ctx context.Context, path string) error
- func (sm *StorageManager) Exists(ctx context.Context, path string) (bool, error)
- func (sm *StorageManager) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (sm *StorageManager) GetDriver(name string) (Storage, error)
- func (sm *StorageManager) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
- func (sm *StorageManager) SetDefaultDriver(name string) error
- func (sm *StorageManager) URL(ctx context.Context, path string) (string, error)
- type StorageServiceProvider
- type ThumbnailConfig
- type UploadConfig
- type UploadResult
- type WatermarkConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type COSConfig ¶
type COSConfig struct {
SecretID string `json:"secret-id"`
SecretKey string `json:"secret-key"`
Region string `json:"region"`
Bucket string `json:"bucket"`
UseSSL bool `json:"use-ssl"`
URLPrefix string `json:"url-prefix"`
DateFormat string `json:"date-format"`
}
COSConfig 腾讯云 COS 配置
type COSStorage ¶
type COSStorage struct {
// contains filtered or unexported fields
}
COSStorage 腾讯云 COS 存储实现
func NewCOSStorage ¶
func NewCOSStorage(config *COSConfig) (*COSStorage, error)
NewCOSStorage 创建 COS 存储实例
func (*COSStorage) Copy ¶
func (c *COSStorage) Copy(ctx context.Context, srcPath, dstPath string) error
Copy 复制文件
func (*COSStorage) Delete ¶
func (c *COSStorage) Delete(ctx context.Context, path string) error
Delete 删除文件
func (*COSStorage) Exists ¶
Exists 检查文件是否存在
func (*COSStorage) Get ¶
func (c *COSStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
Get 获取文件
func (*COSStorage) List ¶
List 列出文件
func (*COSStorage) Move ¶
func (c *COSStorage) Move(ctx context.Context, srcPath, dstPath string) error
Move 移动文件
func (*COSStorage) Put ¶
func (c *COSStorage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
Put 上传文件
func (*COSStorage) PutFile ¶
PutFile 上传本地文件
func (*COSStorage) Size ¶
Size 获取文件大小
type CacheConfig ¶
type CacheConfig struct {
Enabled bool `json:"enabled"`
Driver string `json:"driver"`
TTL int `json:"ttl"`
Prefix string `json:"prefix"`
}
CacheConfig 缓存配置
type FileHandle ¶
type FileHandle struct {
// contains filtered or unexported fields
}
func NewFileHandle ¶
func NewFileHandle(storage *StorageManager) *FileHandle
func (*FileHandle) ModuleName ¶
func (i *FileHandle) ModuleName() (en string, zh string)
func (*FileHandle) Upload ¶
func (i *FileHandle) Upload(ctx *gin.Context)
type FileInfo ¶
type FileInfo struct {
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
ContentType string `json:"content_type"`
Extension string `json:"extension"`
URL string `json:"url"`
Hash string `json:"hash"`
UploadTime time.Time `json:"upload_time"`
Metadata map[string]string `json:"metadata"`
}
FileInfo 文件信息
type ImageConfig ¶
type ImageConfig struct {
Enabled bool `json:"enabled"`
Quality int `json:"quality"`
Formats []string `json:"formats"`
Thumbnails map[string]ThumbnailConfig `json:"thumbnails"`
Watermark WatermarkConfig `json:"watermark"`
}
ImageConfig 图片处理配置
type LocalConfig ¶
type LocalConfig struct {
Root string `json:"root"`
URLPrefix string `json:"url-prefix"`
CreateDirs bool `json:"create-dirs"`
DirMode uint32 `json:"dir-mode"`
FileMode uint32 `json:"file-mode"`
DateFormat string `json:"date-format"`
}
LocalConfig 本地存储配置
type LocalStorage ¶
type LocalStorage struct {
// contains filtered or unexported fields
}
LocalStorage 本地存储实现
func NewLocalStorage ¶
func NewLocalStorage(config *LocalConfig) *LocalStorage
NewLocalStorage 创建本地存储实例
func (*LocalStorage) Copy ¶
func (ls *LocalStorage) Copy(ctx context.Context, srcPath, dstPath string) error
Copy 复制文件
func (*LocalStorage) Delete ¶
func (ls *LocalStorage) Delete(ctx context.Context, path string) error
Delete 删除文件
func (*LocalStorage) Exists ¶
Exists 检查文件是否存在
func (*LocalStorage) Get ¶
func (ls *LocalStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
Get 获取文件
func (*LocalStorage) List ¶
List 列出文件
func (*LocalStorage) Move ¶
func (ls *LocalStorage) Move(ctx context.Context, srcPath, dstPath string) error
Move 移动文件
func (*LocalStorage) Put ¶
func (ls *LocalStorage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
Put 上传文件
func (*LocalStorage) PutFile ¶
func (ls *LocalStorage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
PutFile 上传本地文件
func (*LocalStorage) Size ¶
Size 获取文件大小
type LoggingConfig ¶
type LoggingConfig struct {
Enabled bool `json:"enabled"`
Level string `json:"level"`
LogUpload bool `json:"log-upload"`
LogDownload bool `json:"log-download"`
LogDelete bool `json:"log-delete"`
}
LoggingConfig 日志配置
type MinIOConfig ¶
type MinIOConfig struct {
Endpoint string `json:"endpoint"`
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
UseSSL bool `json:"use-ssl"`
Bucket string `json:"bucket"`
Region string `json:"region"`
URLPrefix string `json:"url-prefix"`
DateFormat string `json:"date-format"`
}
MinIOConfig MinIO 配置
type MinIOStorage ¶
type MinIOStorage struct {
// contains filtered or unexported fields
}
MinIOStorage MinIO 存储实现
func NewMinIOStorage ¶
func NewMinIOStorage(config *MinIOConfig) (*MinIOStorage, error)
NewMinIOStorage 创建 MinIO 存储实例
func (*MinIOStorage) Copy ¶
func (m *MinIOStorage) Copy(ctx context.Context, srcPath, dstPath string) error
Copy 复制文件
func (*MinIOStorage) Delete ¶
func (m *MinIOStorage) Delete(ctx context.Context, path string) error
Delete 删除文件
func (*MinIOStorage) Exists ¶
Exists 检查文件是否存在
func (*MinIOStorage) Get ¶
func (m *MinIOStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
Get 获取文件
func (*MinIOStorage) List ¶
List 列出文件
func (*MinIOStorage) Move ¶
func (m *MinIOStorage) Move(ctx context.Context, srcPath, dstPath string) error
Move 移动文件
func (*MinIOStorage) Put ¶
func (m *MinIOStorage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
Put 上传文件
func (*MinIOStorage) PutFile ¶
func (m *MinIOStorage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
PutFile 上传本地文件
func (*MinIOStorage) Size ¶
Size 获取文件大小
type MonitoringConfig ¶
type MonitoringConfig struct {
Enabled bool `json:"enabled"`
Interval int `json:"interval"`
MonitorSpace bool `json:"monitor-space"`
MonitorFiles bool `json:"monitor-files"`
MonitorSpeed bool `json:"monitor-speed"`
}
MonitoringConfig 监控配置
type OSSConfig ¶
type OSSConfig struct {
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
Endpoint string `json:"endpoint"`
Bucket string `json:"bucket"`
UseSSL bool `json:"use-ssl"`
URLPrefix string `json:"url-prefix"`
DateFormat string `json:"date-format"`
}
OSSConfig 阿里云 OSS 配置
type Options ¶
type Options struct {
Driver string `json:"driver"`
Local LocalConfig `json:"local"`
S3 S3Config `json:"s3"`
MinIO MinIOConfig `json:"minio"`
OSS OSSConfig `json:"oss"`
COS COSConfig `json:"cos"`
Qiniu QiniuConfig `json:"qiniu"`
Upload UploadConfig `json:"upload"`
Image ImageConfig `json:"image"`
Security SecurityConfig `json:"security"`
Cache CacheConfig `json:"cache"`
Logging LoggingConfig `json:"logging"`
Monitoring MonitoringConfig `json:"monitoring"`
}
Options 存储配置选项
type QiniuConfig ¶
type QiniuConfig struct {
AccessKey string `json:"access-key"`
SecretKey string `json:"secret-key"`
Bucket string `json:"bucket"`
Domain string `json:"domain"`
UseSSL bool `json:"use-ssl"`
Zone string `json:"zone"`
DateFormat string `json:"date-format"`
}
QiniuConfig 七牛云配置
type QiniuStorage ¶
type QiniuStorage struct {
// contains filtered or unexported fields
}
QiniuStorage 七牛云存储实现(上传走 storagev2;列举/元数据/删除等走 v1 BucketManager,避免 storagev2/objects 在部分 Go 版本下无法编译)
func NewQiniuStorage ¶
func NewQiniuStorage(config *QiniuConfig) (*QiniuStorage, error)
NewQiniuStorage 创建七牛云存储实例
func (*QiniuStorage) Copy ¶
func (q *QiniuStorage) Copy(ctx context.Context, srcPath, dstPath string) error
Copy 复制文件
func (*QiniuStorage) Delete ¶
func (q *QiniuStorage) Delete(ctx context.Context, path string) error
Delete 删除文件
func (*QiniuStorage) Exists ¶
Exists 检查文件是否存在
func (*QiniuStorage) Get ¶
func (q *QiniuStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)
Get 获取文件
func (*QiniuStorage) List ¶
List 列出文件
func (*QiniuStorage) Move ¶
func (q *QiniuStorage) Move(ctx context.Context, srcPath, dstPath string) error
Move 移动文件
func (*QiniuStorage) Put ¶
func (q *QiniuStorage) Put(ctx context.Context, path string, reader io.Reader, _ int64) (*FileInfo, error)
Put 上传文件
func (*QiniuStorage) PutFile ¶
func (q *QiniuStorage) PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
PutFile 上传本地文件
func (*QiniuStorage) Size ¶
Size 获取文件大小
type S3Config ¶
type S3Config struct {
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
Region string `json:"region"`
Bucket string `json:"bucket"`
Endpoint string `json:"endpoint"`
UseSSL bool `json:"use-ssl"`
PathStyle bool `json:"path-style"`
ACL string `json:"acl"`
URLPrefix string `json:"url-prefix"`
DateFormat string `json:"date-format"`
}
S3Config Amazon S3 配置
type S3Storage ¶
type S3Storage struct {
// contains filtered or unexported fields
}
S3Storage S3 存储实现
func (*S3Storage) Copy ¶
Copy 复制文件
func (*S3Storage) Delete ¶
Delete 删除文件
func (*S3Storage) Exists ¶
Exists 检查文件是否存在
func (*S3Storage) Get ¶
Get 获取文件
func (*S3Storage) List ¶
List 列出文件
func (*S3Storage) Move ¶
Move 移动文件
func (*S3Storage) Put ¶
func (s *S3Storage) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
Put 上传文件
func (*S3Storage) PutFile ¶
PutFile 上传本地文件
func (*S3Storage) Size ¶
Size 获取文件大小
type SecurityConfig ¶
type SecurityConfig struct {
VirusScan bool `json:"virus-scan"`
ScanCommand string `json:"scan-command"`
ContentCheck bool `json:"content-check"`
ForbiddenTypes []string `json:"forbidden-types"`
ForbiddenExtensions []string `json:"forbidden-extensions"`
}
SecurityConfig 安全配置
type Storage ¶
type Storage interface {
// Put 上传文件
Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
// PutFile 上传本地文件
PutFile(ctx context.Context, path string, localPath string) (*FileInfo, error)
// Get 获取文件
Get(ctx context.Context, path string) (io.ReadCloser, error)
// Delete 删除文件
Delete(ctx context.Context, path string) error
// Exists 检查文件是否存在
Exists(ctx context.Context, path string) (bool, error)
// Size 获取文件大小
Size(ctx context.Context, path string) (int64, error)
// URL 获取文件访问 URL
URL(ctx context.Context, path string) (string, error)
// List 列出文件
List(ctx context.Context, prefix string) ([]*FileInfo, error)
// Copy 复制文件
Copy(ctx context.Context, srcPath, dstPath string) error
// Move 移动文件
Move(ctx context.Context, srcPath, dstPath string) error
}
Storage 存储接口
type StorageManager ¶
type StorageManager struct {
// contains filtered or unexported fields
}
StorageManager 存储管理器
func (*StorageManager) AddDriver ¶
func (sm *StorageManager) AddDriver(name string, driver Storage)
AddDriver 添加存储驱动
func (*StorageManager) Default ¶
func (sm *StorageManager) Default() (Storage, error)
Default 获取默认驱动
func (*StorageManager) Delete ¶
func (sm *StorageManager) Delete(ctx context.Context, path string) error
Delete 使用默认驱动删除文件
func (*StorageManager) Exists ¶
Exists 使用默认驱动检查文件是否存在
func (*StorageManager) Get ¶
func (sm *StorageManager) Get(ctx context.Context, path string) (io.ReadCloser, error)
Get 使用默认驱动获取文件
func (*StorageManager) GetDriver ¶
func (sm *StorageManager) GetDriver(name string) (Storage, error)
GetDriver 获取指定驱动
func (*StorageManager) Put ¶
func (sm *StorageManager) Put(ctx context.Context, path string, reader io.Reader, size int64) (*FileInfo, error)
Put 使用默认驱动上传文件
func (*StorageManager) SetDefaultDriver ¶
func (sm *StorageManager) SetDefaultDriver(name string) error
SetDefaultDriver 设置默认驱动
type StorageServiceProvider ¶
type StorageServiceProvider struct {
// contains filtered or unexported fields
}
StorageServiceProvider 存储服务提供者
func (*StorageServiceProvider) Conf ¶
func (s *StorageServiceProvider) Conf() map[string]string
func (*StorageServiceProvider) Description ¶
func (s *StorageServiceProvider) Description() string
type ThumbnailConfig ¶
type ThumbnailConfig struct {
Width int `json:"width"`
Height int `json:"height"`
Mode string `json:"mode"`
}
ThumbnailConfig 缩略图配置
type UploadConfig ¶
type UploadConfig struct {
MaxFileSize int64 `json:"max-file-size"`
AllowedTypes []string `json:"allowed-types"`
AllowedExtensions []string `json:"allowed-extensions"`
CheckFileType bool `json:"check-file-type"`
UniqueFilename bool `json:"unique-filename"`
FilenameStrategy string `json:"filename-strategy"`
KeepOriginalName bool `json:"keep-original-name"`
}
UploadConfig 上传配置
Source Files
¶
- cos.go
- file_handle.go
- local.go
- minio.go
- qiniu.go
- s3.go
- storage.go
- storage_service_provider.go