From e4bccf96b4392f08cbc9d8e508d2accd877d7313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=AC=91?= Date: Tue, 15 Jun 2021 15:05:04 +0800 Subject: [PATCH 1/3] exa_excel_parse.go: fix return err --- server/service/exa_excel_parse.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/service/exa_excel_parse.go b/server/service/exa_excel_parse.go index 19ec3e51..f8a5a356 100644 --- a/server/service/exa_excel_parse.go +++ b/server/service/exa_excel_parse.go @@ -24,8 +24,8 @@ func ParseInfoList2Excel(infoList []model.SysBaseMenu, filePath string) error { menu.Component, }) } - excel.SaveAs(filePath) - return nil + err := excel.SaveAs(filePath) + return err } func ParseExcel2InfoList() ([]model.SysBaseMenu, error) { From ff67f0553fd90cf0018f29e2bbf777c94f525bc1 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Thu, 17 Jun 2021 09:03:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?perf:=E4=BC=98=E5=8C=96=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 创建失败不更改config文件保持,前端保持在init界面 修改文件 - server/api/sys_initdb.go - server/service/sys_initdb.go --- server/api/v1/sys_initdb.go | 3 ++- server/service/sys_initdb.go | 33 +++++++++++---------------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/server/api/v1/sys_initdb.go b/server/api/v1/sys_initdb.go index 7a35819b..ef3b1d4f 100644 --- a/server/api/v1/sys_initdb.go +++ b/server/api/v1/sys_initdb.go @@ -5,6 +5,7 @@ import ( "gin-vue-admin/model/request" "gin-vue-admin/model/response" "gin-vue-admin/service" + "go.uber.org/zap" "github.com/gin-gonic/gin" @@ -30,7 +31,7 @@ func InitDB(c *gin.Context) { } if err := service.InitDB(dbInfo); err != nil { global.GVA_LOG.Error("自动创建数据库失败!", zap.Any("err", err)) - response.FailWithMessage("自动创建数据库失败,请查看后台日志", c) + response.FailWithMessage("自动创建数据库失败,请查看后台日志,检查后在进行初始化", c) return } response.OkWithData("自动创建数据库成功", c) diff --git a/server/service/sys_initdb.go b/server/service/sys_initdb.go index 3880cb05..44e4ec70 100644 --- a/server/service/sys_initdb.go +++ b/server/service/sys_initdb.go @@ -9,10 +9,11 @@ import ( "gin-vue-admin/model/request" "gin-vue-admin/source" "gin-vue-admin/utils" + "path/filepath" + "github.com/spf13/viper" "gorm.io/driver/mysql" "gorm.io/gorm" - "path/filepath" ) //@author: [songzhibin97](https://github.com/songzhibin97) @@ -71,13 +72,6 @@ func initDB(InitDBFunctions ...model.InitDBFunc) (err error) { //@return: error func InitDB(conf request.InitDB) error { - BaseMysql := config.Mysql{ - Path: "", - Dbname: "", - Username: "", - Password: "", - Config: "charset=utf8mb4&parseTime=True&loc=Local", - } if conf.Host == "" { conf.Host = "127.0.0.1" @@ -100,15 +94,11 @@ func InitDB(conf request.InitDB) error { Config: "charset=utf8mb4&parseTime=True&loc=Local", } - if err := writeConfig(global.GVA_VP, MysqlConfig); err != nil { - return err - } - m := global.GVA_CONFIG.Mysql - if m.Dbname == "" { + if MysqlConfig.Dbname == "" { return nil } - linkDns := m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config + linkDns := MysqlConfig.Username + ":" + MysqlConfig.Password + "@tcp(" + MysqlConfig.Path + ")/" + MysqlConfig.Dbname + "?" + MysqlConfig.Config mysqlConfig := mysql.Config{ DSN: linkDns, // DSN data source name DefaultStringSize: 191, // string 类型字段的默认长度 @@ -118,15 +108,11 @@ func InitDB(conf request.InitDB) error { SkipInitializeWithVersion: false, // 根据版本自动配置 } if db, err := gorm.Open(mysql.New(mysqlConfig), &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true}); err != nil { - //global.GVA_LOG.Error("MySQL启动异常!", zap.Any("err", err)) - //os.Exit(0) - //return nil - _ = writeConfig(global.GVA_VP, BaseMysql) return nil } else { sqlDB, _ := db.DB() - sqlDB.SetMaxIdleConns(m.MaxIdleConns) - sqlDB.SetMaxOpenConns(m.MaxOpenConns) + sqlDB.SetMaxIdleConns(MysqlConfig.MaxIdleConns) + sqlDB.SetMaxOpenConns(MysqlConfig.MaxOpenConns) global.GVA_DB = db } @@ -147,7 +133,7 @@ func InitDB(conf request.InitDB) error { model.SysOperationRecord{}, ) if err != nil { - _ = writeConfig(global.GVA_VP, BaseMysql) + global.GVA_DB = nil return err } err = initDB( @@ -163,7 +149,10 @@ func InitDB(conf request.InitDB) error { source.File, source.BaseMenu) if err != nil { - _ = writeConfig(global.GVA_VP, BaseMysql) + global.GVA_DB = nil + return err + } + if err = writeConfig(global.GVA_VP, MysqlConfig); err != nil { return err } global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..") From 4be5ae914900768ddfb478ce562d9f22d5005bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=AC=91?= Date: Thu, 17 Jun 2021 14:51:35 +0800 Subject: [PATCH 3/3] aliyun_oss,qiniu,tencent_cos: fix file open close --- server/utils/upload/aliyun_oss.go | 2 +- server/utils/upload/qiniu.go | 1 + server/utils/upload/tencent_cos.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/server/utils/upload/aliyun_oss.go b/server/utils/upload/aliyun_oss.go index 4eeaaed6..fcba9700 100644 --- a/server/utils/upload/aliyun_oss.go +++ b/server/utils/upload/aliyun_oss.go @@ -25,7 +25,7 @@ func (*AliyunOSS) UploadFile(file *multipart.FileHeader) (string, string, error) 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 diff --git a/server/utils/upload/qiniu.go b/server/utils/upload/qiniu.go index 614c912a..e70ba1fb 100644 --- a/server/utils/upload/qiniu.go +++ b/server/utils/upload/qiniu.go @@ -38,6 +38,7 @@ func (*Qiniu) UploadFile(file *multipart.FileHeader) (string, string, error) { return "", "", errors.New("function file.Open() Filed, 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 { diff --git a/server/utils/upload/tencent_cos.go b/server/utils/upload/tencent_cos.go index 26b25843..b093d9c2 100644 --- a/server/utils/upload/tencent_cos.go +++ b/server/utils/upload/tencent_cos.go @@ -24,6 +24,7 @@ func (*TencentCOS) UploadFile(file *multipart.FileHeader) (string, string, error global.GVA_LOG.Error("function file.Open() Filed", zap.Any("err", openError.Error())) return "", "", errors.New("function file.Open() Filed, 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)