✨ Init
This commit is contained in:
75
utils/upload/aliyun_oss.go
Normal file
75
utils/upload/aliyun_oss.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"mime/multipart"
|
||||
"time"
|
||||
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
"go.uber.org/zap"
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type AliyunOSS struct{}
|
||||
|
||||
func (*AliyunOSS) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||
bucket, err := NewBucket()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("function AliyunOSS.NewBucket() Failed", zap.Any("err", err.Error()))
|
||||
return "", "", errors.New("function AliyunOSS.NewBucket() Failed, err:" + err.Error())
|
||||
}
|
||||
|
||||
// 读取本地文件。
|
||||
f, openError := file.Open()
|
||||
if openError != nil {
|
||||
global.GVA_LOG.Error("function file.Open() Failed", zap.Any("err", openError.Error()))
|
||||
return "", "", errors.New("function file.Open() Failed, err:" + openError.Error())
|
||||
}
|
||||
defer f.Close() // 创建文件 defer 关闭
|
||||
// 上传阿里云路径 文件名格式 自己可以改 建议保证唯一性
|
||||
// yunFileTmpPath := filepath.Join("uploads", time.Now().Format("2006-01-02")) + "/" + file.Filename
|
||||
yunFileTmpPath := global.GVA_CONFIG.AliyunOSS.BasePath + "/" + "uploads" + "/" + time.Now().Format("2006-01-02") + "/" + file.Filename
|
||||
|
||||
// 上传文件流。
|
||||
err = bucket.PutObject(yunFileTmpPath, f)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("function formUploader.Put() Failed", zap.Any("err", err.Error()))
|
||||
return "", "", errors.New("function formUploader.Put() Failed, err:" + err.Error())
|
||||
}
|
||||
|
||||
return global.GVA_CONFIG.AliyunOSS.BucketUrl + "/" + yunFileTmpPath, yunFileTmpPath, nil
|
||||
}
|
||||
|
||||
func (*AliyunOSS) DeleteFile(key string) error {
|
||||
bucket, err := NewBucket()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("function AliyunOSS.NewBucket() Failed", zap.Any("err", err.Error()))
|
||||
return errors.New("function AliyunOSS.NewBucket() Failed, err:" + err.Error())
|
||||
}
|
||||
|
||||
// 删除单个文件。objectName表示删除OSS文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
|
||||
// 如需删除文件夹,请将objectName设置为对应的文件夹名称。如果文件夹非空,则需要将文件夹下的所有object删除后才能删除该文件夹。
|
||||
err = bucket.DeleteObject(key)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("function bucketManager.Delete() failed", zap.Any("err", err.Error()))
|
||||
return errors.New("function bucketManager.Delete() failed, err:" + err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewBucket() (*oss.Bucket, error) {
|
||||
// 创建OSSClient实例。
|
||||
client, err := oss.New(global.GVA_CONFIG.AliyunOSS.Endpoint, global.GVA_CONFIG.AliyunOSS.AccessKeyId, global.GVA_CONFIG.AliyunOSS.AccessKeySecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 获取存储空间。
|
||||
bucket, err := client.Bucket(global.GVA_CONFIG.AliyunOSS.BucketName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bucket, nil
|
||||
}
|
97
utils/upload/aws_s3.go
Normal file
97
utils/upload/aws_s3.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
"time"
|
||||
|
||||
"miniapp/global"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AwsS3 struct{}
|
||||
|
||||
//@author: [WqyJh](https://github.com/WqyJh)
|
||||
//@object: *AwsS3
|
||||
//@function: UploadFile
|
||||
//@description: Upload file to Aws S3 using aws-sdk-go. See https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/s3-example-basic-bucket-operations.html#s3-examples-bucket-ops-upload-file-to-bucket
|
||||
//@param: file *multipart.FileHeader
|
||||
//@return: string, string, error
|
||||
|
||||
func (*AwsS3) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||
session := newSession()
|
||||
uploader := s3manager.NewUploader(session)
|
||||
|
||||
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename)
|
||||
filename := global.GVA_CONFIG.AwsS3.PathPrefix + "/" + fileKey
|
||||
f, openError := file.Open()
|
||||
if openError != nil {
|
||||
global.GVA_LOG.Error("function file.Open() failed", zap.Any("err", openError.Error()))
|
||||
return "", "", errors.New("function file.Open() failed, err:" + openError.Error())
|
||||
}
|
||||
defer f.Close() // 创建文件 defer 关闭
|
||||
|
||||
_, err := uploader.Upload(&s3manager.UploadInput{
|
||||
Bucket: aws.String(global.GVA_CONFIG.AwsS3.Bucket),
|
||||
Key: aws.String(filename),
|
||||
Body: f,
|
||||
})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("function uploader.Upload() failed", zap.Any("err", err.Error()))
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return global.GVA_CONFIG.AwsS3.BaseURL + "/" + filename, fileKey, nil
|
||||
}
|
||||
|
||||
//@author: [WqyJh](https://github.com/WqyJh)
|
||||
//@object: *AwsS3
|
||||
//@function: DeleteFile
|
||||
//@description: Delete file from Aws S3 using aws-sdk-go. See https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/s3-example-basic-bucket-operations.html#s3-examples-bucket-ops-delete-bucket-item
|
||||
//@param: file *multipart.FileHeader
|
||||
//@return: string, string, error
|
||||
|
||||
func (*AwsS3) DeleteFile(key string) error {
|
||||
session := newSession()
|
||||
svc := s3.New(session)
|
||||
filename := global.GVA_CONFIG.AwsS3.PathPrefix + "/" + key
|
||||
bucket := global.GVA_CONFIG.AwsS3.Bucket
|
||||
|
||||
_, err := svc.DeleteObject(&s3.DeleteObjectInput{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(filename),
|
||||
})
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("function svc.DeleteObject() failed", zap.Any("err", err.Error()))
|
||||
return errors.New("function svc.DeleteObject() failed, err:" + err.Error())
|
||||
}
|
||||
|
||||
_ = svc.WaitUntilObjectNotExists(&s3.HeadObjectInput{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(filename),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// newSession Create S3 session
|
||||
func newSession() *session.Session {
|
||||
sess, _ := session.NewSession(&aws.Config{
|
||||
Region: aws.String(global.GVA_CONFIG.AwsS3.Region),
|
||||
Endpoint: aws.String(global.GVA_CONFIG.AwsS3.Endpoint), //minio在这里设置地址,可以兼容
|
||||
S3ForcePathStyle: aws.Bool(global.GVA_CONFIG.AwsS3.S3ForcePathStyle),
|
||||
DisableSSL: aws.Bool(global.GVA_CONFIG.AwsS3.DisableSSL),
|
||||
Credentials: credentials.NewStaticCredentials(
|
||||
global.GVA_CONFIG.AwsS3.SecretID,
|
||||
global.GVA_CONFIG.AwsS3.SecretKey,
|
||||
"",
|
||||
),
|
||||
})
|
||||
return sess
|
||||
}
|
86
utils/upload/local.go
Normal file
86
utils/upload/local.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"miniapp/global"
|
||||
"miniapp/utils"
|
||||
)
|
||||
|
||||
type Local struct{}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@author: [ccfish86](https://github.com/ccfish86)
|
||||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
||||
//@object: *Local
|
||||
//@function: UploadFile
|
||||
//@description: 上传文件
|
||||
//@param: file *multipart.FileHeader
|
||||
//@return: string, string, error
|
||||
|
||||
func (*Local) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||
// 读取文件后缀
|
||||
ext := path.Ext(file.Filename)
|
||||
// 读取文件名并加密
|
||||
name := strings.TrimSuffix(file.Filename, ext)
|
||||
name = utils.MD5V([]byte(name))
|
||||
// 拼接新文件名
|
||||
filename := name + "_" + time.Now().Format("20060102150405") + ext
|
||||
// 尝试创建此路径
|
||||
mkdirErr := os.MkdirAll(global.GVA_CONFIG.Local.StorePath, os.ModePerm)
|
||||
if mkdirErr != nil {
|
||||
global.GVA_LOG.Error("function os.MkdirAll() failed", zap.Any("err", mkdirErr.Error()))
|
||||
return "", "", errors.New("function os.MkdirAll() failed, err:" + mkdirErr.Error())
|
||||
}
|
||||
// 拼接路径和文件名
|
||||
p := global.GVA_CONFIG.Local.StorePath + "/" + filename
|
||||
filepath := global.GVA_CONFIG.Local.Path + "/" + filename
|
||||
|
||||
f, openError := file.Open() // 读取文件
|
||||
if openError != nil {
|
||||
global.GVA_LOG.Error("function file.Open() failed", zap.Any("err", openError.Error()))
|
||||
return "", "", errors.New("function file.Open() failed, err:" + openError.Error())
|
||||
}
|
||||
defer f.Close() // 创建文件 defer 关闭
|
||||
|
||||
out, createErr := os.Create(p)
|
||||
if createErr != nil {
|
||||
global.GVA_LOG.Error("function os.Create() failed", zap.Any("err", createErr.Error()))
|
||||
|
||||
return "", "", errors.New("function os.Create() failed, err:" + createErr.Error())
|
||||
}
|
||||
defer out.Close() // 创建文件 defer 关闭
|
||||
|
||||
_, copyErr := io.Copy(out, f) // 传输(拷贝)文件
|
||||
if copyErr != nil {
|
||||
global.GVA_LOG.Error("function io.Copy() failed", zap.Any("err", copyErr.Error()))
|
||||
return "", "", errors.New("function io.Copy() failed, err:" + copyErr.Error())
|
||||
}
|
||||
return filepath, filename, nil
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@author: [ccfish86](https://github.com/ccfish86)
|
||||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
||||
//@object: *Local
|
||||
//@function: DeleteFile
|
||||
//@description: 删除文件
|
||||
//@param: key string
|
||||
//@return: error
|
||||
|
||||
func (*Local) DeleteFile(key string) error {
|
||||
p := global.GVA_CONFIG.Local.StorePath + "/" + key
|
||||
if strings.Contains(p, global.GVA_CONFIG.Local.StorePath) {
|
||||
if err := os.Remove(p); err != nil {
|
||||
return errors.New("本地文件删除失败, err:" + err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
67
utils/upload/obs.go
Normal file
67
utils/upload/obs.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"mime/multipart"
|
||||
|
||||
"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
|
||||
"github.com/pkg/errors"
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
var HuaWeiObs = new(Obs)
|
||||
|
||||
type Obs struct{}
|
||||
|
||||
func NewHuaWeiObsClient() (client *obs.ObsClient, err error) {
|
||||
return obs.New(global.GVA_CONFIG.HuaWeiObs.AccessKey, global.GVA_CONFIG.HuaWeiObs.SecretKey, global.GVA_CONFIG.HuaWeiObs.Endpoint)
|
||||
}
|
||||
|
||||
func (o *Obs) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||
// var open multipart.File
|
||||
open, err := file.Open()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
defer open.Close()
|
||||
filename := file.Filename
|
||||
input := &obs.PutObjectInput{
|
||||
PutObjectBasicInput: obs.PutObjectBasicInput{
|
||||
ObjectOperationInput: obs.ObjectOperationInput{
|
||||
Bucket: global.GVA_CONFIG.HuaWeiObs.Bucket,
|
||||
Key: filename,
|
||||
},
|
||||
ContentType: file.Header.Get("content-type"),
|
||||
},
|
||||
Body: open,
|
||||
}
|
||||
|
||||
var client *obs.ObsClient
|
||||
client, err = NewHuaWeiObsClient()
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "获取华为对象存储对象失败!")
|
||||
}
|
||||
|
||||
_, err = client.PutObject(input)
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "文件上传失败!")
|
||||
}
|
||||
filepath := global.GVA_CONFIG.HuaWeiObs.Path + "/" + filename
|
||||
return filepath, filename, err
|
||||
}
|
||||
|
||||
func (o *Obs) DeleteFile(key string) error {
|
||||
client, err := NewHuaWeiObsClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "获取华为对象存储对象失败!")
|
||||
}
|
||||
input := &obs.DeleteObjectInput{
|
||||
Bucket: global.GVA_CONFIG.HuaWeiObs.Bucket,
|
||||
Key: key,
|
||||
}
|
||||
var output *obs.DeleteObjectOutput
|
||||
output, err = client.DeleteObject(input)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "删除对象(%s)失败!, output: %v", key, output)
|
||||
}
|
||||
return nil
|
||||
}
|
96
utils/upload/qiniu.go
Normal file
96
utils/upload/qiniu.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
"time"
|
||||
|
||||
"github.com/qiniu/api.v7/v7/auth/qbox"
|
||||
"github.com/qiniu/api.v7/v7/storage"
|
||||
"go.uber.org/zap"
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type Qiniu struct{}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@author: [ccfish86](https://github.com/ccfish86)
|
||||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
||||
//@object: *Qiniu
|
||||
//@function: UploadFile
|
||||
//@description: 上传文件
|
||||
//@param: file *multipart.FileHeader
|
||||
//@return: string, string, error
|
||||
|
||||
func (*Qiniu) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||
putPolicy := storage.PutPolicy{Scope: global.GVA_CONFIG.Qiniu.Bucket}
|
||||
mac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)
|
||||
upToken := putPolicy.UploadToken(mac)
|
||||
cfg := qiniuConfig()
|
||||
formUploader := storage.NewFormUploader(cfg)
|
||||
ret := storage.PutRet{}
|
||||
putExtra := storage.PutExtra{Params: map[string]string{"x:name": "github logo"}}
|
||||
|
||||
f, openError := file.Open()
|
||||
if openError != nil {
|
||||
global.GVA_LOG.Error("function file.Open() failed", zap.Any("err", openError.Error()))
|
||||
|
||||
return "", "", errors.New("function file.Open() failed, err:" + openError.Error())
|
||||
}
|
||||
defer f.Close() // 创建文件 defer 关闭
|
||||
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename) // 文件名格式 自己可以改 建议保证唯一性
|
||||
putErr := formUploader.Put(context.Background(), &ret, upToken, fileKey, f, file.Size, &putExtra)
|
||||
if putErr != nil {
|
||||
global.GVA_LOG.Error("function formUploader.Put() failed", zap.Any("err", putErr.Error()))
|
||||
return "", "", errors.New("function formUploader.Put() failed, err:" + putErr.Error())
|
||||
}
|
||||
return global.GVA_CONFIG.Qiniu.ImgPath + "/" + ret.Key, ret.Key, nil
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@author: [ccfish86](https://github.com/ccfish86)
|
||||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
||||
//@object: *Qiniu
|
||||
//@function: DeleteFile
|
||||
//@description: 删除文件
|
||||
//@param: key string
|
||||
//@return: error
|
||||
|
||||
func (*Qiniu) DeleteFile(key string) error {
|
||||
mac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)
|
||||
cfg := qiniuConfig()
|
||||
bucketManager := storage.NewBucketManager(mac, cfg)
|
||||
if err := bucketManager.Delete(global.GVA_CONFIG.Qiniu.Bucket, key); err != nil {
|
||||
global.GVA_LOG.Error("function bucketManager.Delete() failed", zap.Any("err", err.Error()))
|
||||
return errors.New("function bucketManager.Delete() failed, err:" + err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
||||
//@object: *Qiniu
|
||||
//@function: qiniuConfig
|
||||
//@description: 根据配置文件进行返回七牛云的配置
|
||||
//@return: *storage.Config
|
||||
|
||||
func qiniuConfig() *storage.Config {
|
||||
cfg := storage.Config{
|
||||
UseHTTPS: global.GVA_CONFIG.Qiniu.UseHTTPS,
|
||||
UseCdnDomains: global.GVA_CONFIG.Qiniu.UseCdnDomains,
|
||||
}
|
||||
switch global.GVA_CONFIG.Qiniu.Zone { // 根据配置文件进行初始化空间对应的机房
|
||||
case "ZoneHuadong":
|
||||
cfg.Zone = &storage.ZoneHuadong
|
||||
case "ZoneHuabei":
|
||||
cfg.Zone = &storage.ZoneHuabei
|
||||
case "ZoneHuanan":
|
||||
cfg.Zone = &storage.ZoneHuanan
|
||||
case "ZoneBeimei":
|
||||
cfg.Zone = &storage.ZoneBeimei
|
||||
case "ZoneXinjiapo":
|
||||
cfg.Zone = &storage.ZoneXinjiapo
|
||||
}
|
||||
return &cfg
|
||||
}
|
61
utils/upload/tencent_cos.go
Normal file
61
utils/upload/tencent_cos.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"miniapp/global"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type TencentCOS struct{}
|
||||
|
||||
// UploadFile upload file to COS
|
||||
func (*TencentCOS) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||
client := NewClient()
|
||||
f, openError := file.Open()
|
||||
if openError != nil {
|
||||
global.GVA_LOG.Error("function file.Open() failed", zap.Any("err", openError.Error()))
|
||||
return "", "", errors.New("function file.Open() failed, err:" + openError.Error())
|
||||
}
|
||||
defer f.Close() // 创建文件 defer 关闭
|
||||
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename)
|
||||
|
||||
_, err := client.Object.Put(context.Background(), global.GVA_CONFIG.TencentCOS.PathPrefix+"/"+fileKey, f, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return global.GVA_CONFIG.TencentCOS.BaseURL + "/" + global.GVA_CONFIG.TencentCOS.PathPrefix + "/" + fileKey, fileKey, nil
|
||||
}
|
||||
|
||||
// DeleteFile delete file form COS
|
||||
func (*TencentCOS) DeleteFile(key string) error {
|
||||
client := NewClient()
|
||||
name := global.GVA_CONFIG.TencentCOS.PathPrefix + "/" + key
|
||||
_, err := client.Object.Delete(context.Background(), name)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("function bucketManager.Delete() failed", zap.Any("err", err.Error()))
|
||||
return errors.New("function bucketManager.Delete() failed, err:" + err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewClient init COS client
|
||||
func NewClient() *cos.Client {
|
||||
urlStr, _ := url.Parse("https://" + global.GVA_CONFIG.TencentCOS.Bucket + ".cos." + global.GVA_CONFIG.TencentCOS.Region + ".myqcloud.com")
|
||||
baseURL := &cos.BaseURL{BucketURL: urlStr}
|
||||
client := cos.NewClient(baseURL, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: global.GVA_CONFIG.TencentCOS.SecretID,
|
||||
SecretKey: global.GVA_CONFIG.TencentCOS.SecretKey,
|
||||
},
|
||||
})
|
||||
return client
|
||||
}
|
37
utils/upload/upload.go
Normal file
37
utils/upload/upload.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"mime/multipart"
|
||||
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
// OSS 对象存储接口
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
// Author [ccfish86](https://github.com/ccfish86)
|
||||
type OSS interface {
|
||||
UploadFile(file *multipart.FileHeader) (string, string, error)
|
||||
DeleteFile(key string) error
|
||||
}
|
||||
|
||||
// NewOss OSS的实例化方法
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
// Author [ccfish86](https://github.com/ccfish86)
|
||||
func NewOss() OSS {
|
||||
switch global.GVA_CONFIG.System.OssType {
|
||||
case "local":
|
||||
return &Local{}
|
||||
case "qiniu":
|
||||
return &Qiniu{}
|
||||
case "tencent-cos":
|
||||
return &TencentCOS{}
|
||||
case "aliyun-oss":
|
||||
return &AliyunOSS{}
|
||||
case "huawei-obs":
|
||||
return HuaWeiObs
|
||||
case "aws-s3":
|
||||
return &AwsS3{}
|
||||
default:
|
||||
return &Local{}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user