解决err覆盖问题

This commit is contained in:
SliverHorn
2020-11-16 18:38:20 +08:00
parent 7a47f59945
commit a890bd2d38
13 changed files with 93 additions and 53 deletions

View File

@@ -4,6 +4,7 @@ import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"github.com/gookit/color"
"os"
"time"
"gorm.io/gorm"
@@ -78,8 +79,8 @@ var Apis = []model.SysApi{
{global.GVA_MODEL{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"},
}
func InitSysApi(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
func InitSysApi(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ?", []int{1, 67}).Find(&[]model.SysApi{}).RowsAffected == 2 {
color.Danger.Println("sys_apis表的初始数据已存在!")
return nil
@@ -88,5 +89,8 @@ func InitSysApi(db *gorm.DB) (err error) {
return err
}
return nil
})
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_apis 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
}