解决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

@@ -3,6 +3,7 @@ package datas
import (
"github.com/gookit/color"
"gorm.io/gorm"
"os"
)
type SysAuthorityMenus struct {
@@ -66,8 +67,8 @@ var AuthorityMenus = []SysAuthorityMenus{
{"9528", 20},
}
func InitSysAuthorityMenus(db *gorm.DB) (err error) {
return db.Table("sys_authority_menus").Transaction(func(tx *gorm.DB) error {
func InitSysAuthorityMenus(db *gorm.DB) {
if err := db.Table("sys_authority_menus").Transaction(func(tx *gorm.DB) error {
if tx.Where("sys_authority_authority_id IN ?", []string{"888", "8881", "9528"}).Find(&[]SysAuthorityMenus{}).RowsAffected == 53 {
color.Danger.Println("sys_authority_menus表的初始数据已存在!")
return nil
@@ -76,5 +77,8 @@ func InitSysAuthorityMenus(db *gorm.DB) (err error) {
return err
}
return nil
})
}); err != nil {
color.Warn.Printf("[Mysql]--> sys_authority_menus 表的初始数据失败,err: %v\n", err)
os.Exit(0)
}
}