fix: resp 多参数问题
This commit is contained in:
44
resp/resp.go
44
resp/resp.go
@ -43,22 +43,44 @@ func RE(c *gin.Context, err error) {
|
||||
|
||||
func _r(c *gin.Context, r *res, args ...any) {
|
||||
length := len(args)
|
||||
switch length {
|
||||
case 0:
|
||||
break
|
||||
case 1:
|
||||
if msg, ok := args[0].(string); ok {
|
||||
r.Msg = msg
|
||||
|
||||
if length == 0 {
|
||||
goto END
|
||||
}
|
||||
case 2:
|
||||
r.Data = args[1]
|
||||
case 3:
|
||||
r.Err = args[2]
|
||||
case 4:
|
||||
|
||||
if length >= 4 {
|
||||
goto H4
|
||||
}
|
||||
|
||||
if length >= 3 {
|
||||
goto H3
|
||||
}
|
||||
|
||||
if length >= 2 {
|
||||
goto H2
|
||||
}
|
||||
if length >= 1 {
|
||||
goto H1
|
||||
}
|
||||
|
||||
H4:
|
||||
if code, err := cast.ToIntE(args[3]); err == nil {
|
||||
r.Code = code
|
||||
}
|
||||
H3:
|
||||
if es, ok := args[2].(error); ok {
|
||||
r.Err = es.Error()
|
||||
} else {
|
||||
r.Err = args[2]
|
||||
}
|
||||
H2:
|
||||
r.Data = args[1]
|
||||
H1:
|
||||
if msg, ok := args[0].(string); ok {
|
||||
r.Msg = msg
|
||||
}
|
||||
|
||||
END:
|
||||
|
||||
if r.Msg == "" {
|
||||
r.Msg = Msg(r.Status)
|
||||
|
9
resp/resp_test.go
Normal file
9
resp/resp_test.go
Normal file
@ -0,0 +1,9 @@
|
||||
package resp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResp(t *testing.T) {
|
||||
|
||||
}
|
Reference in New Issue
Block a user