Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
5df55a364d | |||
002f5f15fb |
@ -3,6 +3,7 @@ package resp
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/spf13/cast"
|
||||||
)
|
)
|
||||||
|
|
||||||
type res struct {
|
type res struct {
|
||||||
@ -10,6 +11,8 @@ type res struct {
|
|||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
Data any `json:"data"`
|
Data any `json:"data"`
|
||||||
Err any `json:"err"`
|
Err any `json:"err"`
|
||||||
|
// Deprecated: 200:1, other: -1
|
||||||
|
Code int `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func R200(c *gin.Context, data any, msgs ...string) {
|
func R200(c *gin.Context, data any, msgs ...string) {
|
||||||
@ -17,6 +20,7 @@ func R200(c *gin.Context, data any, msgs ...string) {
|
|||||||
Status: 200,
|
Status: 200,
|
||||||
Msg: Msg200,
|
Msg: Msg200,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
Code: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msgs) > 0 && msgs[0] != "" {
|
if len(msgs) > 0 && msgs[0] != "" {
|
||||||
@ -50,6 +54,10 @@ func _r(c *gin.Context, r *res, args ...any) {
|
|||||||
r.Data = args[1]
|
r.Data = args[1]
|
||||||
case 3:
|
case 3:
|
||||||
r.Err = args[2]
|
r.Err = args[2]
|
||||||
|
case 4:
|
||||||
|
if code, err := cast.ToIntE(args[3]); err == nil {
|
||||||
|
r.Code = code
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Msg == "" {
|
if r.Msg == "" {
|
||||||
|
12
tool/gin.go
Normal file
12
tool/gin.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package tool
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func Local(c *gin.Context, key string) any {
|
||||||
|
data, ok := c.Get(key)
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
Reference in New Issue
Block a user