Skip to content

Commit 76ccbcc

Browse files
authored
Merge pull request flipped-aurora#72 from flipped-aurora/gin-vue-admin_v2_dev
Gin vue admin v2 dev
2 parents bb26faf + ab6b15b commit 76ccbcc

File tree

9 files changed

+235
-203
lines changed

9 files changed

+235
-203
lines changed

server/Dockerfile

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
FROM centos:7.6.1810
1+
FROM golang:alpine as builder
2+
RUN apk add --update --no-cache yarn make g++
23

3-
# 设置go mod proxy 国内代理
4-
# 设置golang path
5-
ENV GOPROXY=https://goproxy.io GOPATH=/gopath PATH="${PATH}:/usr/local/go/bin"
6-
# 定义使用的Golang 版本
7-
ARG GO_VERSION=1.13.3
4+
ENV GOPROXY=https://goproxy.cn,https://goproxy.io,direct \
5+
GO111MODULE=on \
6+
CGO_ENABLED=1
7+
WORKDIR /go/src/gin-vue-admin
8+
RUN go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
9+
COPY . .
10+
RUN go env && go list && go build -v -a -ldflags "-extldflags \"-static\" " -o gvadmin .
811

9-
# 安装 golang 1.13.3
10-
RUN yum install -y wget && \
11-
yum install -y wqy-microhei-fonts wqy-zenhei-fonts && \
12-
wget "https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz" && \
13-
rm -rf /usr/local/go && \
14-
tar -C /usr/local -xzf "go$GO_VERSION.linux-amd64.tar.gz" && \
15-
rm -rf *.tar.gz && \
16-
go version && go env;
17-
18-
19-
WORKDIR $GOPATH
20-
COPY . gin-vue
21-
22-
RUN cd gin-vue && go build -o app;
12+
WORKDIR /app
13+
COPY --from=builder /go/src/gin-vue-admin/gvadmin .
14+
COPY --from=builder /go/src/gin-vue-admin/db.db .
15+
COPY --from=builder /go/src/gin-vue-admin/config.yaml .
16+
COPY --from=builder /go/src/gin-vue-admin/resource ./resource
2317

2418
EXPOSE 8888
2519

26-
CMD ["gin-vue/app"]
20+
CMD ["gvadmin/app"]
21+

server/api/v1/exa_file_upload_download.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func UploadFile(c *gin.Context) {
2727
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
2828
} else {
2929
//文件上传后拿到文件路径
30-
err, filePath, key := utils.Upload(header, USER_HEADER_BUCKET, USER_HEADER_IMG_PATH)
30+
err, filePath, key := utils.Upload(header)
3131
if err != nil {
3232
response.FailWithMessage(fmt.Sprintf("接收返回值失败,%v", err), c)
3333
} else {
@@ -45,7 +45,6 @@ func UploadFile(c *gin.Context) {
4545
response.FailWithMessage(fmt.Sprintf("修改数据库链接失败,%v", err), c)
4646
} else {
4747
response.OkDetailed(resp.ExaFileResponse{File: file}, "上传成功", c)
48-
4948
}
5049
}
5150
}
@@ -65,7 +64,7 @@ func DeleteFile(c *gin.Context) {
6564
if err != nil {
6665
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
6766
} else {
68-
err = utils.DeleteFile(USER_HEADER_BUCKET, f.Key)
67+
err = utils.DeleteFile(f.Key)
6968
if err != nil {
7069
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
7170

server/api/v1/sys_user.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ import (
1818
"time"
1919
)
2020

21-
const (
22-
USER_HEADER_IMG_PATH string = "http://qmplusimg.henrongyi.top"
23-
USER_HEADER_BUCKET string = "qm-plus-img"
24-
)
25-
2621
// @Tags Base
2722
// @Summary 用户注册账号
2823
// @Produce application/json
@@ -172,7 +167,7 @@ func UploadHeaderImg(c *gin.Context) {
172167
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
173168
} else {
174169
//文件上传后拿到文件路径
175-
err, filePath, _ := utils.Upload(header, USER_HEADER_BUCKET, USER_HEADER_IMG_PATH)
170+
err, filePath, _ := utils.Upload(header)
176171
if err != nil {
177172
response.FailWithMessage(fmt.Sprintf("接收返回值失败,%v", err), c)
178173
} else {

server/config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ mysql:
1717
config: 'charset=utf8&parseTime=True&loc=Local'
1818
max-idle-conns: 10
1919
max-open-conns: 10
20-
log-mode: true
20+
log-mode: false
21+
2122
#sqlite 配置
2223
sqlite:
2324
path: db.db
2425
log-mode: true
2526
config: 'loc=Asia/Shanghai'
27+
2628
# oss configuration
2729
qiniu:
2830
access-key: '25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ'
2931
secret-key: 'pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY'
30-
32+
bucket: 'qm-plus-img'
33+
img-path: 'http://qmplusimg.henrongyi.top'
3134
# redis configuration
3235
redis:
3336
addr: '127.0.0.1:6379'

server/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type Redis struct {
4646
type Qiniu struct {
4747
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"`
4848
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
49+
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
50+
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"`
4951
}
5052

5153
type Captcha struct {

server/initialize/mysql.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"gin-vue-admin/global"
55
"github.com/jinzhu/gorm"
66
_ "github.com/jinzhu/gorm/dialects/mysql"
7+
"os"
78
)
89

910
//初始化数据库并产生数据库全局变量
1011
func Mysql() {
1112
admin := global.GVA_CONFIG.Mysql
1213
if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
13-
global.GVA_LOG.Error("DEFAULTDB数据库启动异常", err)
14+
global.GVA_LOG.Error("MySQL启动异常", err)
15+
os.Exit(0)
1416
} else {
1517
global.GVA_DB = db
1618
global.GVA_DB.DB().SetMaxIdleConns(admin.MaxIdleConns)

server/utils/upload.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ import (
1010
"time"
1111
)
1212

13-
var accessKey string = global.GVA_CONFIG.Qiniu.AccessKey // 你在七牛云的accessKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
14-
var secretKey string = global.GVA_CONFIG.Qiniu.SecretKey // 你在七牛云的secretKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
15-
1613
// 接收两个参数 一个文件流 一个 bucket 你的七牛云标准空间的名字
17-
func Upload(file *multipart.FileHeader, bucket string, urlPath string) (err error, path string, key string) {
14+
func Upload(file *multipart.FileHeader) (err error, path string, key string) {
1815
putPolicy := storage.PutPolicy{
19-
Scope: bucket,
16+
Scope: global.GVA_CONFIG.Qiniu.Bucket,
2017
}
21-
mac := qbox.NewMac(accessKey, secretKey)
18+
mac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)
2219
upToken := putPolicy.UploadToken(mac)
2320
cfg := storage.Config{}
2421
// 空间对应的机房
@@ -43,16 +40,15 @@ func Upload(file *multipart.FileHeader, bucket string, urlPath string) (err erro
4340
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename) // 文件名格式 自己可以改 建议保证唯一性
4441
err = formUploader.Put(context.Background(), &ret, upToken, fileKey, f, dataLen, &putExtra)
4542
if err != nil {
46-
fmt.Println(err)
47-
//qmlog.QMLog.Info(err)
43+
global.GVA_LOG.Error("upload file fail:", err)
4844
return err, "", ""
4945
}
50-
return err, urlPath + "/" + ret.Key, ret.Key
46+
return err, global.GVA_CONFIG.Qiniu.ImgPath + "/" + ret.Key, ret.Key
5147
}
5248

53-
func DeleteFile(bucket string, key string) error {
49+
func DeleteFile(key string) error {
5450

55-
mac := qbox.NewMac(accessKey, secretKey)
51+
mac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)
5652
cfg := storage.Config{
5753
// 是否使用https域名进行资源管理
5854
UseHTTPS: false,
@@ -61,7 +57,7 @@ func DeleteFile(bucket string, key string) error {
6157
// 如果没有特殊需求,默认不需要指定
6258
//cfg.Zone=&storage.ZoneHuabei
6359
bucketManager := storage.NewBucketManager(mac, &cfg)
64-
err := bucketManager.Delete(bucket, key)
60+
err := bucketManager.Delete(global.GVA_CONFIG.Qiniu.Bucket, key)
6561
if err != nil {
6662
fmt.Println(err)
6763
return err

0 commit comments

Comments
 (0)