任务一完成
This commit is contained in:
parent
35ab7c0b70
commit
77887aa76b
|
|
@ -29,8 +29,8 @@ func NewAliyun(endpoint, accessKeyID, accessKeySecret, bucketName, bucketURL, ba
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (a *Aliyun) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (a *Aliyun) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
client, err := oss.New(a.Endpoint, a.AccessKeyID, a.AccessKeySecret)
|
client, err := oss.New(a.Endpoint, a.AccessKeyID, a.AccessKeySecret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
|
|
@ -63,8 +63,8 @@ func (a *Aliyun) Upload(file *multipart.FileHeader) (string, string, error) {
|
||||||
return accessURL, key, nil
|
return accessURL, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (a *Aliyun) Delete(key string) error {
|
func (a *Aliyun) DeleteFile(key string) error {
|
||||||
client, err := oss.New(a.Endpoint, a.AccessKeyID, a.AccessKeySecret)
|
client, err := oss.New(a.Endpoint, a.AccessKeyID, a.AccessKeySecret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ func (a *AwsS3) getClient(ctx context.Context) (*s3.Client, error) {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (a *AwsS3) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (a *AwsS3) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client, err := a.getClient(ctx)
|
client, err := a.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -94,8 +94,8 @@ func (a *AwsS3) Upload(file *multipart.FileHeader) (string, string, error) {
|
||||||
return accessURL, key, nil
|
return accessURL, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (a *AwsS3) Delete(key string) error {
|
func (a *AwsS3) DeleteFile(key string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client, err := a.getClient(ctx)
|
client, err := a.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ func (c *CloudflareR2) getClient(ctx context.Context) (*s3.Client, error) {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (c *CloudflareR2) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (c *CloudflareR2) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client, err := c.getClient(ctx)
|
client, err := c.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -88,8 +88,8 @@ func (c *CloudflareR2) Upload(file *multipart.FileHeader) (string, string, error
|
||||||
return accessURL, key, nil
|
return accessURL, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (c *CloudflareR2) Delete(key string) error {
|
func (c *CloudflareR2) DeleteFile(key string) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client, err := c.getClient(ctx)
|
client, err := c.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ func (h *HuaweiObs) getClient() (*obs.ObsClient, error) {
|
||||||
return obs.New(h.AccessKey, h.SecretKey, h.Endpoint)
|
return obs.New(h.AccessKey, h.SecretKey, h.Endpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (h *HuaweiObs) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (h *HuaweiObs) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
client, err := h.getClient()
|
client, err := h.getClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
|
|
@ -66,8 +66,8 @@ func (h *HuaweiObs) Upload(file *multipart.FileHeader) (string, string, error) {
|
||||||
return accessURL, key, nil
|
return accessURL, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (h *HuaweiObs) Delete(key string) error {
|
func (h *HuaweiObs) DeleteFile(key string) error {
|
||||||
client, err := h.getClient()
|
client, err := h.getClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ func NewLocal(storePath, basePath string) *Local {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (l *Local) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (l *Local) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
// 生成文件名和路径
|
// 生成文件名和路径
|
||||||
fileName := GenerateFileName(file.Filename)
|
fileName := GenerateFileName(file.Filename)
|
||||||
filePath := GeneratePath(l.BasePath)
|
filePath := GeneratePath(l.BasePath)
|
||||||
|
|
@ -59,8 +59,8 @@ func (l *Local) Upload(file *multipart.FileHeader) (string, string, error) {
|
||||||
return accessPath, key, nil
|
return accessPath, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (l *Local) Delete(key string) error {
|
func (l *Local) DeleteFile(key string) error {
|
||||||
fullPath := path.Join(l.StorePath, key)
|
fullPath := path.Join(l.StorePath, key)
|
||||||
return os.Remove(fullPath)
|
return os.Remove(fullPath)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ func (m *Minio) getClient() (*minio.Client, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (m *Minio) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (m *Minio) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
client, err := m.getClient()
|
client, err := m.getClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
|
|
@ -74,8 +74,8 @@ func (m *Minio) Upload(file *multipart.FileHeader) (string, string, error) {
|
||||||
return accessURL, key, nil
|
return accessURL, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (m *Minio) Delete(key string) error {
|
func (m *Minio) DeleteFile(key string) error {
|
||||||
client, err := m.getClient()
|
client, err := m.getClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ func (q *Qiniu) getZone() *storage.Region {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (q *Qiniu) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (q *Qiniu) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
mac := qbox.NewMac(q.AccessKey, q.SecretKey)
|
mac := qbox.NewMac(q.AccessKey, q.SecretKey)
|
||||||
putPolicy := storage.PutPolicy{Scope: q.Bucket}
|
putPolicy := storage.PutPolicy{Scope: q.Bucket}
|
||||||
upToken := putPolicy.UploadToken(mac)
|
upToken := putPolicy.UploadToken(mac)
|
||||||
|
|
@ -87,8 +87,8 @@ func (q *Qiniu) Upload(file *multipart.FileHeader) (string, string, error) {
|
||||||
return accessURL, key, nil
|
return accessURL, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (q *Qiniu) Delete(key string) error {
|
func (q *Qiniu) DeleteFile(key string) error {
|
||||||
mac := qbox.NewMac(q.AccessKey, q.SecretKey)
|
mac := qbox.NewMac(q.AccessKey, q.SecretKey)
|
||||||
cfg := storage.Config{Zone: q.getZone()}
|
cfg := storage.Config{Zone: q.getZone()}
|
||||||
bucketManager := storage.NewBucketManager(mac, &cfg)
|
bucketManager := storage.NewBucketManager(mac, &cfg)
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ func (t *Tencent) getClient() *cos.Client {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// UploadFile 上传文件
|
||||||
func (t *Tencent) Upload(file *multipart.FileHeader) (string, string, error) {
|
func (t *Tencent) UploadFile(file *multipart.FileHeader) (string, string, error) {
|
||||||
client := t.getClient()
|
client := t.getClient()
|
||||||
|
|
||||||
// 生成文件名和路径
|
// 生成文件名和路径
|
||||||
|
|
@ -71,8 +71,8 @@ func (t *Tencent) Upload(file *multipart.FileHeader) (string, string, error) {
|
||||||
return accessURL, key, nil
|
return accessURL, key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除文件
|
// DeleteFile 删除文件
|
||||||
func (t *Tencent) Delete(key string) error {
|
func (t *Tencent) DeleteFile(key string) error {
|
||||||
client := t.getClient()
|
client := t.getClient()
|
||||||
_, err := client.Object.Delete(context.Background(), key)
|
_, err := client.Object.Delete(context.Background(), key)
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ var (
|
||||||
|
|
||||||
// OSS 对象存储接口
|
// OSS 对象存储接口
|
||||||
type OSS interface {
|
type OSS interface {
|
||||||
Upload(file *multipart.FileHeader) (string, string, error)
|
UploadFile(file *multipart.FileHeader) (string, string, error)
|
||||||
Delete(key string) error
|
DeleteFile(key string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config 上传配置
|
// Config 上传配置
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue