Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c8460fc44 | |||
5df55a364d |
4
opt/opt.go
Normal file
4
opt/opt.go
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package opt
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
}
|
10
resp/resp.go
10
resp/resp.go
@ -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 {
|
||||||
@ -53,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 == "" {
|
||||||
@ -65,6 +70,7 @@ func _r(c *gin.Context, r *res, args ...any) {
|
|||||||
func R400(c *gin.Context, args ...any) {
|
func R400(c *gin.Context, args ...any) {
|
||||||
r := &res{
|
r := &res{
|
||||||
Status: 400,
|
Status: 400,
|
||||||
|
Code: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
_r(c, r, args...)
|
_r(c, r, args...)
|
||||||
@ -73,6 +79,7 @@ func R400(c *gin.Context, args ...any) {
|
|||||||
func R401(c *gin.Context, args ...any) {
|
func R401(c *gin.Context, args ...any) {
|
||||||
r := &res{
|
r := &res{
|
||||||
Status: 401,
|
Status: 401,
|
||||||
|
Code: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
_r(c, r, args...)
|
_r(c, r, args...)
|
||||||
@ -81,6 +88,7 @@ func R401(c *gin.Context, args ...any) {
|
|||||||
func R403(c *gin.Context, args ...any) {
|
func R403(c *gin.Context, args ...any) {
|
||||||
r := &res{
|
r := &res{
|
||||||
Status: 403,
|
Status: 403,
|
||||||
|
Code: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
_r(c, r, args...)
|
_r(c, r, args...)
|
||||||
@ -89,6 +97,7 @@ func R403(c *gin.Context, args ...any) {
|
|||||||
func R500(c *gin.Context, args ...any) {
|
func R500(c *gin.Context, args ...any) {
|
||||||
r := &res{
|
r := &res{
|
||||||
Status: 500,
|
Status: 500,
|
||||||
|
Code: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
_r(c, r, args...)
|
_r(c, r, args...)
|
||||||
@ -97,6 +106,7 @@ func R500(c *gin.Context, args ...any) {
|
|||||||
func R501(c *gin.Context, args ...any) {
|
func R501(c *gin.Context, args ...any) {
|
||||||
r := &res{
|
r := &res{
|
||||||
Status: 501,
|
Status: 501,
|
||||||
|
Code: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
_r(c, r, args...)
|
_r(c, r, args...)
|
||||||
|
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
|
||||||
|
}
|
@ -11,3 +11,8 @@ func Must(errs ...error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MustWithData[T any](data T, err error) T {
|
||||||
|
Must(err)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user