Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梁国权
gin-vue-admin
提交
43fae5f9
G
gin-vue-admin
项目概览
梁国权
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
43fae5f9
编写于
2月 22, 2021
作者:
M
MUHM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add TencentCOS support to OSS
上级
c8ce87df
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
83 addition
and
1 deletion
+83
-1
server/config.yaml
server/config.yaml
+9
-0
server/config/config.go
server/config/config.go
+1
-0
server/config/oss.go
server/config/oss.go
+9
-0
server/go.mod
server/go.mod
+1
-0
server/utils/upload/tencent_cos.go
server/utils/upload/tencent_cos.go
+60
-0
server/utils/upload/upload.go
server/utils/upload/upload.go
+3
-1
未找到文件。
server/config.yaml
浏览文件 @
43fae5f9
...
...
@@ -78,6 +78,15 @@ qiniu:
secret-key
:
'
pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY'
use-cdn-domains
:
false
# tencent cos configuration
tencent-cos
:
bucket
:
'
xxxxx-10005608'
region
:
'
ap-shanghai'
secret-id
:
'
xxxxxxxx'
secret-key
:
'
xxxxxxxx'
base-url
:
'
https://gin.vue.admin'
path-prefix
:
'
gin-vue-admin'
# excel configuration
excel
:
dir
:
'
./resource/excel/'
\ No newline at end of file
server/config/config.go
浏览文件 @
43fae5f9
...
...
@@ -13,5 +13,6 @@ type Server struct {
// oss
Local
Local
`mapstructure:"local" json:"local" yaml:"local"`
Qiniu
Qiniu
`mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
TencentCOS
TencentCOS
`mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
Excel
Excel
`mapstructure:"excel" json:"excel" yaml:"excel"`
}
server/config/oss.go
浏览文件 @
43fae5f9
...
...
@@ -13,3 +13,12 @@ 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
TencentCOS
struct
{
Bucket
string
`mapstructure:"bucket" json:"bucket" yaml:"bucket"`
Region
string
`mapstructure:"region" json:"region" yaml:"region"`
SecretID
string
`mapstructure:"secret-id" json:"secretID" yaml:"secret-id"`
SecretKey
string
`mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
BaseURL
string
`mapstructure:"base-url" json:"baseURL" yaml:"base-url"`
PathPrefix
string
`mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"`
}
server/go.mod
浏览文件 @
43fae5f9
...
...
@@ -46,6 +46,7 @@ require (
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.6.7
github.com/tebeka/strftime v0.1.3 // indirect
github.com/tencentyun/cos-go-sdk-v5 v0.7.19
github.com/unrolled/secure v1.0.7
go.uber.org/zap v1.10.0
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
...
...
server/utils/upload/tencent_cos.go
0 → 100644
浏览文件 @
43fae5f9
package
upload
import
(
"context"
"errors"
"fmt"
"gin-vue-admin/global"
"mime/multipart"
"net/http"
"net/url"
"time"
"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
)
{
c
:=
NewClient
()
f
,
openError
:=
file
.
Open
()
if
openError
!=
nil
{
global
.
GVA_LOG
.
Error
(
"function file.Open() Filed"
,
zap
.
Any
(
"err"
,
openError
.
Error
()))
return
""
,
""
,
errors
.
New
(
"function file.Open() Filed, err:"
+
openError
.
Error
())
}
fileKey
:=
fmt
.
Sprintf
(
"%d%s"
,
time
.
Now
()
.
Unix
(),
file
.
Filename
)
_
,
err
:=
c
.
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
{
c
:=
NewClient
()
name
:=
global
.
GVA_CONFIG
.
TencentCOS
.
PathPrefix
+
"/"
+
key
_
,
err
:=
c
.
Object
.
Delete
(
context
.
Background
(),
name
)
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
}
// NewClient init COS client
func
NewClient
()
*
cos
.
Client
{
u
,
_
:=
url
.
Parse
(
"https://"
+
global
.
GVA_CONFIG
.
TencentCOS
.
Bucket
+
".cos."
+
global
.
GVA_CONFIG
.
TencentCOS
.
Region
+
".myqcloud.com"
)
b
:=
&
cos
.
BaseURL
{
BucketURL
:
u
}
c
:=
cos
.
NewClient
(
b
,
&
http
.
Client
{
Transport
:
&
cos
.
AuthorizationTransport
{
SecretID
:
global
.
GVA_CONFIG
.
TencentCOS
.
SecretID
,
SecretKey
:
global
.
GVA_CONFIG
.
TencentCOS
.
SecretKey
,
},
})
return
c
}
server/utils/upload/upload.go
浏览文件 @
43fae5f9
...
...
@@ -28,6 +28,8 @@ func NewOss() OSS {
return
&
Local
{}
case
"qiniu"
:
return
&
Qiniu
{}
case
"tencent-cos"
:
return
&
TencentCOS
{}
default
:
return
&
Local
{}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录