Documentation
¶
Index ¶
- Constants
- func InitDefaultStorage(config *Config) error
- type AliyunOSS
- func (s *AliyunOSS) Delete(path string) error
- func (s *AliyunOSS) Exists(path string) (bool, error)
- func (s *AliyunOSS) GetInfo(path string) (*FileInfo, error)
- func (s *AliyunOSS) GetURL(path string, expires time.Duration) (string, error)
- func (s *AliyunOSS) Upload(path string, file io.Reader, contentType string) (string, error)
- func (s *AliyunOSS) UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)
- type Config
- type FileInfo
- type LocalStorage
- func (s *LocalStorage) Delete(path string) error
- func (s *LocalStorage) Exists(path string) (bool, error)
- func (s *LocalStorage) GetInfo(path string) (*FileInfo, error)
- func (s *LocalStorage) GetURL(path string, expires time.Duration) (string, error)
- func (s *LocalStorage) Upload(path string, file io.Reader, contentType string) (string, error)
- func (s *LocalStorage) UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)
- type MinIoConf
- type MinioOSS
- type Storage
- type UploadOptions
Constants ¶
View Source
const ( TypeLocal = "local" TypeAliyun = "aliyun" TypeMinio = "minio" )
StorageType 存储类型常量
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AliyunOSS ¶
type AliyunOSS struct {
// contains filtered or unexported fields
}
AliyunOSS 阿里云OSS存储
func NewAliyunOSS ¶
NewAliyunOSS 创建阿里云OSS存储 使用前需要安装: go get github.com/aliyun/aliyun-oss-go-sdk/oss
func (*AliyunOSS) UploadWithOptions ¶
func (s *AliyunOSS) UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)
UploadWithOptions 带选项的上传
type Config ¶
type Config struct {
Type string `mapstructure:"type"` // 存储类型:local, aliyun
Endpoint string `mapstructure:"endpoint"` // 端点地址
Bucket string `mapstructure:"bucket"` // 存储桶名称
AccessKey string `mapstructure:"accessKey"` // 访问密钥ID
SecretKey string `mapstructure:"secretKey"` // 访问密钥Secret
Region string `mapstructure:"region"` // 区域
Domain string `mapstructure:"domain"` // 自定义域名(CDN)
IsPrivate bool `mapstructure:"isPrivate"` // 是否私有(影响URL生成)
BasePath string `mapstructure:"basePath"` // 基础路径
}
Config 存储配置
type FileInfo ¶
type FileInfo struct {
Path string // 文件路径
Size int64 // 文件大小(字节)
ContentType string // MIME类型
LastModified time.Time // 最后修改时间
ETag string // ETag
URL string // 访问URL
}
FileInfo 文件信息
type LocalStorage ¶
type LocalStorage struct {
// contains filtered or unexported fields
}
LocalStorage 本地存储
func NewLocalStorage ¶
func NewLocalStorage(basePath, baseURL string) *LocalStorage
NewLocalStorage 创建本地存储
func (*LocalStorage) Exists ¶
func (s *LocalStorage) Exists(path string) (bool, error)
Exists 检查文件是否存在
func (*LocalStorage) GetInfo ¶
func (s *LocalStorage) GetInfo(path string) (*FileInfo, error)
GetInfo 获取文件信息
func (*LocalStorage) UploadWithOptions ¶
func (s *LocalStorage) UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)
UploadWithOptions 带选项的上传
type MinIoConf ¶ added in v0.3.43
type MinIoConf struct {
MinIOAccessKeyID string `json:"minIOAccessKeyID"` //admin
MinIOAccessSecretKey string `json:"minIOAccessSecretKey"` //MinIOAccessSecretKey
MinIOEndpoint string `json:"minIOEndpoint"` //localhost:9000
MinIOBucketLocation string `json:"minIOBucketLocation"` //cn-north-1
MinIOSSLBool bool `json:"minIOSSLBool"`
MinIOBucket string `json:"minIOBucket"` //mymusic
MinIOBasePath string `json:"minIoBasePath"`
}
type MinioOSS ¶ added in v0.3.43
type MinioOSS struct {
// contains filtered or unexported fields
}
func NewMinioOSS ¶ added in v0.3.43
func (*MinioOSS) DeleteFile ¶ added in v0.3.43
func (*MinioOSS) UploadFile ¶ added in v0.3.43
type Storage ¶
type Storage interface {
// Upload 上传文件
// path: 存储路径(如:uploads/2024/01/01/file.jpg)
// file: 文件内容
// contentType: 文件MIME类型
Upload(path string, file io.Reader, contentType string) (string, error)
// UploadWithOptions 带选项的上传
UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)
// Delete 删除文件
Delete(path string) error
// GetURL 获取文件访问URL
// path: 存储路径
// expires: 过期时间(0表示永久,>0表示生成临时签名URL)
GetURL(path string, expires time.Duration) (string, error)
// Exists 检查文件是否存在
Exists(path string) (bool, error)
// GetInfo 获取文件信息
GetInfo(path string) (*FileInfo, error)
}
Storage 对象存储接口(支持多种云服务商)
var DefaultStorage Storage
DefaultStorage 全局默认存储实例
Click to show internal directories.
Click to hide internal directories.