Documentation
¶
Index ¶
- Constants
- type AliYunConf
- 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 AwsConf
- type AwsOSS
- type CloudflareR2Conf
- type Config
- type FileInfo
- type HuaWeiConf
- type HwOSS
- type LocalConf
- type LocalOSS
- type MinIoConf
- type MinioOSS
- type OSS
- type OSSConf
- type OssType
- type QiNiuConf
- type QiNiuOSS
- type Storage
- type TencentConf
- type TencentOSS
- type UploadInfo
- type UploadOptions
Constants ¶
View Source
const ( TypeLocal = "local" TypeAliyun = "aliyun" )
StorageType 存储类型常量
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AliYunConf ¶
type AliyunOSS ¶ added in v0.3.40
type AliyunOSS struct {
// contains filtered or unexported fields
}
AliyunOSS 阿里云OSS存储
func NewAliyunOSS ¶ added in v0.3.40
NewAliyunOSS 创建阿里云OSS存储 使用前需要安装: go get github.com/aliyun/aliyun-oss-go-sdk/oss
func (*AliyunOSS) UploadWithOptions ¶ added in v0.3.40
func (s *AliyunOSS) UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)
UploadWithOptions 带选项的上传
type AwsConf ¶
type AwsConf struct {
Bucket string `json:"bucket"`
Region string `json:"region"`
Endpoint string `json:"endpoint"`
SecretID string `json:"secret-id"`
SecretKey string `json:"secret-key"`
BaseURL string `json:"base-url"`
PathPrefix string `json:"path-prefix"`
S3ForcePathStyle bool `json:"s3-force-path-style"`
DisableSSL bool `json:"disable-ssl"`
}
type AwsOSS ¶
type AwsOSS struct {
Conf AwsConf
}
func (*AwsOSS) DeleteFile ¶
func (*AwsOSS) UploadFile ¶
func (*AwsOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
type CloudflareR2Conf ¶
type Config ¶ added in v0.3.40
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 ¶ added in v0.3.40
type FileInfo struct {
Path string // 文件路径
Size int64 // 文件大小(字节)
ContentType string // MIME类型
LastModified time.Time // 最后修改时间
ETag string // ETag
URL string // 访问URL
}
FileInfo 文件信息
type HuaWeiConf ¶
type HwOSS ¶
type HwOSS struct {
Conf HuaWeiConf
}
func NewHwOSS ¶
func NewHwOSS(conf HuaWeiConf) *HwOSS
func (*HwOSS) DeleteFile ¶
func (*HwOSS) UploadFile ¶
func (*HwOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
type LocalOSS ¶
type LocalOSS struct {
// contains filtered or unexported fields
}
func NewLocalOSS ¶
func (*LocalOSS) DeleteFile ¶
func (*LocalOSS) UploadFile ¶
func (m *LocalOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
type MinIoConf ¶
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 ¶
type MinioOSS struct {
// contains filtered or unexported fields
}
func NewMinioOSS ¶
func (*MinioOSS) DeleteFile ¶
func (*MinioOSS) UploadFile ¶
func (m *MinioOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
type OSS ¶
type OSS interface {
UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
DeleteFile(key string) error
}
type OSSConf ¶
type OSSConf struct {
Type OssType `json:"type"`
LocalConf LocalConf `json:"localConf,omitempty,optional"`
MinIoConf MinIoConf `json:"minioConf,omitempty,optional"`
AliYunConf AliYunConf `json:"aliyunConf,omitempty,optional"`
TencentConf TencentConf `json:"tencentConf,omitempty,optional"`
QiNiuConf QiNiuConf `json:"qiNiuConf,omitempty,optional"`
AwsConf AwsConf `json:"awsConf,omitempty,optional"`
HuaWeiConf HuaWeiConf `json:"huaWeiConf,omitempty,optional"`
}
type QiNiuConf ¶
type QiNiuConf struct {
Zone string `json:"zone"` // 存储区域
Bucket string `json:"bucket"` // 空间名称
ImgPath string `json:"img-path"` // CDN加速域名
AccessKey string `json:"access-key"` // 秘钥AK
SecretKey string `json:"secret-key"` // 秘钥SK
UseHTTPS bool `json:"use-https"` // 是否使用https
UseCdnDomains bool `json:"use-cdn-domains"` // 上传是否使用CDN上传加速
}
type QiNiuOSS ¶
type QiNiuOSS struct {
Conf QiNiuConf
}
func NewQiNiuOSS ¶
func (*QiNiuOSS) DeleteFile ¶
func (*QiNiuOSS) UploadFile ¶
func (*QiNiuOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
type Storage ¶ added in v0.3.40
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 对象存储接口(支持多种云服务商)
type TencentConf ¶
type TencentOSS ¶
type TencentOSS struct {
Conf TencentConf
}
func NewTencentOSS ¶
func NewTencentOSS(conf TencentConf) *TencentOSS
func (*TencentOSS) DeleteFile ¶
func (*TencentOSS) DeleteFile(key string) error
func (*TencentOSS) UploadFile ¶
func (*TencentOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
type UploadInfo ¶
Click to show internal directories.
Click to hide internal directories.