mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
fix: 问题修复
This commit is contained in:
@@ -56,7 +56,7 @@ func NotNil(data interface{}, msg string) {
|
||||
}
|
||||
|
||||
func NotBlank(data interface{}, msg string) {
|
||||
if utils.IsBlank(reflect.ValueOf(data)) {
|
||||
if utils.IsBlank(data) {
|
||||
panic(NewBizErr(msg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/logger"
|
||||
"mayfly-go/pkg/utils"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -72,12 +71,12 @@ func LogHandler(rc *Ctx) error {
|
||||
|
||||
func getLogMsg(rc *Ctx) string {
|
||||
msg := rc.LogInfo.Description + fmt.Sprintf(" ->%dms", rc.timed)
|
||||
if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) {
|
||||
if !utils.IsBlank(rc.ReqParam) {
|
||||
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
|
||||
}
|
||||
|
||||
// 返回结果不为空,则记录返回结果
|
||||
if rc.LogInfo.LogResp && !utils.IsBlank(reflect.ValueOf(rc.ResData)) {
|
||||
if rc.LogInfo.LogResp && !utils.IsBlank(rc.ResData) {
|
||||
msg = msg + fmt.Sprintf("\n<-- %s", utils.ToString(rc.ResData))
|
||||
}
|
||||
return msg
|
||||
@@ -85,7 +84,7 @@ func getLogMsg(rc *Ctx) string {
|
||||
|
||||
func getErrMsg(rc *Ctx, err interface{}) string {
|
||||
msg := rc.LogInfo.Description
|
||||
if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) {
|
||||
if !utils.IsBlank(rc.ReqParam) {
|
||||
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
|
||||
}
|
||||
|
||||
|
||||
@@ -635,20 +635,24 @@ func Case2Camel(name string) string {
|
||||
return strings.Replace(name, " ", "", -1)
|
||||
}
|
||||
|
||||
func IsBlank(value reflect.Value) bool {
|
||||
switch value.Kind() {
|
||||
case reflect.String:
|
||||
return value.Len() == 0
|
||||
case reflect.Bool:
|
||||
return !value.Bool()
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return value.Int() == 0
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return value.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return value.Float() == 0
|
||||
case reflect.Interface, reflect.Ptr:
|
||||
return value.IsNil()
|
||||
func IsBlank(value any) bool {
|
||||
if value == nil {
|
||||
return true
|
||||
}
|
||||
return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
|
||||
rValue := reflect.ValueOf(value)
|
||||
switch rValue.Kind() {
|
||||
case reflect.String:
|
||||
return rValue.Len() == 0
|
||||
case reflect.Bool:
|
||||
return !rValue.Bool()
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return rValue.Int() == 0
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return rValue.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return rValue.Float() == 0
|
||||
case reflect.Interface, reflect.Ptr:
|
||||
return rValue.IsNil()
|
||||
}
|
||||
return reflect.DeepEqual(rValue.Interface(), reflect.Zero(rValue.Type()).Interface())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user