Documentation
¶
Index ¶
- Variables
- func GeneratePath(ctx context.Context, baseDir, fileName string) string
- func GetMimeType(filename string) string
- type Config
- type FileStorage
- type LocalStorage
- func (s *LocalStorage) Delete(ctx context.Context, path string) error
- func (s *LocalStorage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *LocalStorage) Load(ctx context.Context, path string) ([]byte, error)
- func (s *LocalStorage) Save(ctx context.Context, path string, data []byte) error
- func (s *LocalStorage) URL(path string) string
- func (s *LocalStorage) URLWithContext(ctx context.Context, path string) string
- type S3Storage
- func (s *S3Storage) Delete(ctx context.Context, path string) error
- func (s *S3Storage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *S3Storage) Load(ctx context.Context, path string) ([]byte, error)
- func (s *S3Storage) Save(ctx context.Context, path string, data []byte) error
- func (s *S3Storage) URL(path string) string
- func (s *S3Storage) URLWithContext(ctx context.Context, path string) string
- type Storage
- func (s *Storage) Delete(ctx context.Context, path string) error
- func (s *Storage) Get(ctx context.Context, path string) (*os.File, error)
- func (s *Storage) GetEndpoint() string
- func (s *Storage) GetEndpointWithContext(ctx context.Context) string
- func (s *Storage) GetStream(ctx context.Context, path string) (io.ReadCloser, error)
- func (s *Storage) GetURL(ctx context.Context, path string) (string, error)
- func (s *Storage) List(ctx context.Context, path string) ([]*oss.Object, error)
- func (s *Storage) Put(ctx context.Context, path string, reader io.Reader) error
Constants ¶
This section is empty.
Variables ¶
View Source
var MimeTypes = map[string]string{
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".webp": "image/webp",
".svg": "image/svg+xml",
".bmp": "image/bmp",
".pdf": "application/pdf",
".doc": "application/msword",
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".xls": "application/vnd.ms-excel",
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
".ppt": "application/vnd.ms-powerpoint",
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
".mp3": "audio/mpeg",
".mp4": "video/mp4",
".zip": "application/zip",
".rar": "application/x-rar-compressed",
".txt": "text/plain",
".html": "text/html",
".css": "text/css",
".js": "application/javascript",
".json": "application/json",
".xml": "application/xml",
}
常用文件类型的MIME映射
View Source
var Module = fx.Options( fx.Provide(NewFileStorage), fx.Provide(NewStorage), )
Module 文件存储模块
Functions ¶
func GeneratePath ¶
GeneratePath 生成存储路径
Types ¶
type Config ¶
type Config struct {
Type types.StorageType `json:"type"` // 存储类型
Path string `json:"path"` // 本地存储路径
URL string `json:"url"` // 访问URL
AccessKey string `json:"access_key"` // 访问密钥
SecretKey string `json:"secret_key"` // 访问密钥
Region string `json:"region"` // 区域
Bucket string `json:"bucket"` // 桶名称
Endpoint string `json:"endpoint"` // 端点
}
Config 存储配置
type FileStorage ¶
type FileStorage interface {
// Save 保存文件
Save(ctx context.Context, path string, data []byte) error
// Load 加载文件
Load(ctx context.Context, path string) ([]byte, error)
// Delete 删除文件
Delete(ctx context.Context, path string) error
// List 列出文件
List(ctx context.Context, prefix string) ([]string, error)
// URL 获取文件URL
URL(path string) string
// URLWithContext 使用上下文获取文件URL
URLWithContext(ctx context.Context, path string) string
}
FileStorage 文件存储接口
func NewFileStorage ¶
NewFileStorage 创建文件存储
type LocalStorage ¶
type LocalStorage struct {
// contains filtered or unexported fields
}
LocalStorage 本地文件存储
func NewLocalStorage ¶
func NewLocalStorage(cfg *configs.Config) (*LocalStorage, error)
NewLocalStorage 创建本地文件存储
func (*LocalStorage) Delete ¶
func (s *LocalStorage) Delete(ctx context.Context, path string) error
Delete 删除文件
func (*LocalStorage) URLWithContext ¶
func (s *LocalStorage) URLWithContext(ctx context.Context, path string) string
URLWithContext 使用上下文获取文件URL
type S3Storage ¶
type S3Storage struct {
}
S3Storage S3文件存储
func NewS3Storage ¶
NewS3Storage 创建S3文件存储
type Storage ¶
type Storage struct {
Config Config
// contains filtered or unexported fields
}
Storage 存储服务
func NewStorage ¶
NewStorage 创建存储服务
func (*Storage) GetEndpointWithContext ¶
GetEndpointWithContext 使用上下文获取存储端点
Click to show internal directories.
Click to hide internal directories.