mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 07:50:25 +08:00
refactor: 新增base.Repo与base.App,重构repo与app层代码
This commit is contained in:
@@ -2,43 +2,41 @@ package biz
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/pkg/logx"
|
||||
"mayfly-go/pkg/errorx"
|
||||
"mayfly-go/pkg/utils/anyx"
|
||||
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func ErrIsNil(err error, msg string, params ...any) {
|
||||
// 断言错误为ni
|
||||
// @param msgAndParams 消息与参数占位符,第一位为错误消息可包含%s等格式化标识。其余为Sprintf格式化值内容
|
||||
//
|
||||
// ErrIsNil(err)
|
||||
// ErrIsNil(err, "xxxx")
|
||||
// ErrIsNil(err, "xxxx: %s", "yyyy")
|
||||
func ErrIsNil(err error, msgAndParams ...any) {
|
||||
if err != nil {
|
||||
// logx.ErrorTrace(msg, err)
|
||||
panic(NewBizErr(fmt.Sprintf(msg, params...)))
|
||||
if len(msgAndParams) == 0 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
panic(errorx.NewBiz(fmt.Sprintf(msgAndParams[0].(string), msgAndParams[1:]...)))
|
||||
}
|
||||
}
|
||||
|
||||
func ErrIsNilAppendErr(err error, msg string) {
|
||||
if err != nil {
|
||||
// logx.ErrorTrace(msg, err)
|
||||
panic(NewBizErr(fmt.Sprintf(msg, err.Error())))
|
||||
}
|
||||
}
|
||||
|
||||
func IsNil(err error) {
|
||||
switch t := err.(type) {
|
||||
case *BizError:
|
||||
panic(t)
|
||||
case error:
|
||||
logx.Error("非业务异常: " + err.Error())
|
||||
panic(NewBizErr(fmt.Sprintf("非业务异常: %s", err.Error())))
|
||||
panic(errorx.NewBiz(fmt.Sprintf(msg, err.Error())))
|
||||
}
|
||||
}
|
||||
|
||||
func IsTrue(exp bool, msg string, params ...any) {
|
||||
if !exp {
|
||||
panic(NewBizErr(fmt.Sprintf(msg, params...)))
|
||||
panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
|
||||
}
|
||||
}
|
||||
|
||||
func IsTrueBy(exp bool, err BizError) {
|
||||
func IsTrueBy(exp bool, err errorx.BizError) {
|
||||
if !exp {
|
||||
panic(err)
|
||||
}
|
||||
@@ -46,30 +44,30 @@ func IsTrueBy(exp bool, err BizError) {
|
||||
|
||||
func NotEmpty(str string, msg string, params ...any) {
|
||||
if str == "" {
|
||||
panic(NewBizErr(fmt.Sprintf(msg, params...)))
|
||||
panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
|
||||
}
|
||||
}
|
||||
|
||||
func NotNil(data any, msg string, params ...any) {
|
||||
if reflect.ValueOf(data).IsNil() {
|
||||
panic(NewBizErr(fmt.Sprintf(msg, params...)))
|
||||
panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
|
||||
}
|
||||
}
|
||||
|
||||
func NotBlank(data any, msg string, params ...any) {
|
||||
if anyx.IsBlank(data) {
|
||||
panic(NewBizErr(fmt.Sprintf(msg, params...)))
|
||||
panic(errorx.NewBiz(fmt.Sprintf(msg, params...)))
|
||||
}
|
||||
}
|
||||
|
||||
func IsEquals(data any, data1 any, msg string) {
|
||||
if data != data1 {
|
||||
panic(NewBizErr(msg))
|
||||
panic(errorx.NewBiz(msg))
|
||||
}
|
||||
}
|
||||
|
||||
func Nil(data any, msg string) {
|
||||
if !reflect.ValueOf(data).IsNil() {
|
||||
panic(NewBizErr(msg))
|
||||
panic(errorx.NewBiz(msg))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user