Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GVA - 2021/03/07版本合并 #1

Merged
merged 27 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
43fae5f
add TencentCOS support to OSS
Feb 22, 2021
8cfb4c6
add aliyun oss support
Feb 24, 2021
b494f66
更新了某些文本 让提示更加友好
piexlmax Feb 26, 2021
4b03d2c
Merge pull request #381 from MUHM/develop
piexlmax Feb 27, 2021
9fc2472
Merge branch 'develop' into develop
piexlmax Feb 27, 2021
ac8b8cd
Merge pull request #384 from lauyang/develop
piexlmax Feb 27, 2021
e36e9a1
更新了某些文本 让提示更加友好
piexlmax Feb 26, 2021
625ff31
对合并代码进行微调
piexlmax Feb 27, 2021
d5221a6
前端系统配置增加 tencent-cos aliyun-oss 配置
piexlmax Feb 27, 2021
f42e3a2
新增api重启系统(支持非windows)
songzhibin97 Feb 27, 2021
1e9baff
Update sys_system.go
songzhibin97 Feb 27, 2021
e8dcaba
Merge pull request #386 from songzhibin97/gva_gormv2_dev
piexlmax Feb 27, 2021
a8bf931
字典样式修改
piexlmax Feb 27, 2021
ae42da9
新增功能-api生成数据库并初始化回写配置
songzhibin97 Feb 27, 2021
8b27c39
Merge branch 'gva_gormv2_dev' of https://github.com/flipped-aurora/gi…
piexlmax Mar 1, 2021
ddd802f
订正了swagger
songzhibin97 Mar 2, 2021
1e271b1
补充修改
songzhibin97 Mar 2, 2021
da27c85
补充修改
songzhibin97 Mar 2, 2021
ded39b9
Merge pull request #387 from songzhibin97/gva_gormv2_dev
piexlmax Mar 2, 2021
7363fa5
包位置调整
piexlmax Mar 2, 2021
18ef727
自动初始化数据库功能后端部分完成
piexlmax Mar 4, 2021
517e057
cmd剔除 初始数据结构转移 修复初始携带apibug
piexlmax Mar 4, 2021
d9a9b4e
修复初始apibug
piexlmax Mar 4, 2021
9b23ef9
自动初始化整体调试完成
piexlmax Mar 4, 2021
ceee5a8
自动初始化中间件拦截 防止误操作无法进入初始化功能
piexlmax Mar 4, 2021
431e0d6
版本号更改提交
piexlmax Mar 5, 2021
890862c
Merge remote-tracking branch 'origin/master'
piexlmax Mar 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add aliyun oss support
  • Loading branch information
yang.liu06 committed Feb 24, 2021
commit 8cfb4c682f5c42072b89440694a86561226bc0ef
8 changes: 8 additions & 0 deletions server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ qiniu:
secret-key: 'pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY'
use-cdn-domains: false

# aliyun oss configuration
aliyun-oss:
endpoint: 'yourEndpoint'
access-key-id: 'yourAccessKeyId'
access-key-secret: 'yourAccessKeySecret'
bucket-name: 'yourBucketName'
bucket-url: 'yourBucketUrl'

# excel configuration
excel:
dir: './resource/excel/'
9 changes: 5 additions & 4 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ type Server struct {
System System `mapstructure:"system" json:"system" yaml:"system"`
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
// gorm
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
// oss
Local Local `mapstructure:"local" json:"local" yaml:"local"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
Local Local `mapstructure:"local" json:"local" yaml:"local"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
}
8 changes: 8 additions & 0 deletions server/config/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ type Qiniu struct {
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"`
}

type AliyunOSS struct {
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
AccessKeyId string `mapstructure:"access-key-id" json:"accessKeyId" yaml:"access-key-id"`
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"`
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"`
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"`
}
2 changes: 2 additions & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.2
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/casbin/casbin v1.9.1
github.com/casbin/casbin/v2 v2.11.0
github.com/casbin/gorm-adapter/v3 v3.0.2
Expand Down
74 changes: 74 additions & 0 deletions server/utils/upload/aliyun_oss.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package upload

import (
"errors"
"gin-vue-admin/global"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"go.uber.org/zap"
"mime/multipart"
"path/filepath"
"time"
)

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())
}

//上传阿里云路径 文件名格式 自己可以改 建议保证唯一性
yunFileTmpPath := filepath.Join("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() Filed", zap.Any("err", err.Error()))
return errors.New("function bucketManager.Delete() Filed, 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
}