解决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
+7 -3
View File
@@ -3,6 +3,7 @@ package datas
import (
"gin-vue-admin/global"
"github.com/gookit/color"
"os"
"time"
"gin-vue-admin/model"
@@ -13,8 +14,8 @@ var Customers = []model.ExaCustomer{
{GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
}
func InitExaCustomer(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
func InitExaCustomer(db *gorm.DB) {
if err := db.Transaction(func(tx *gorm.DB) error {
if tx.Where("id IN ? ", []int{1}).Find(&[]model.ExaCustomer{}).RowsAffected == 1 {
color.Danger.Println("exa_customers表的初始数据已存在!")
return nil
@@ -23,5 +24,8 @@ func InitExaCustomer(db *gorm.DB) (err error) {
return err
}
return nil
})
}); err != nil {
color.Warn.Printf("[Mysql]--> exa_customers 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
}