Commit 4cd0b18a by zhengqiuyun86

go升级,泛型使用

parent 4b8063fb
...@@ -2,16 +2,25 @@ package util ...@@ -2,16 +2,25 @@ package util
import ( import (
"bytes" "bytes"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"io" "io"
"net/http" "net/http"
"strings" "strings"
) )
func Param[T any](c *gin.Context, key string) *T { func Param[T any](c *gin.Context, key string) T {
if val, ok := c.Get(key); ok && val != nil { val, ok := c.Get(key)
i, _ := val.(T) if ok {
return &i exception.ThrowsErrS("PARAMS_ERR", fmt.Sprintf("参数[%s]必传", key))
} else {
i, k := val.(T)
if k {
return i
} else {
exception.ThrowsErrS("PARAMS_ERR", fmt.Sprintf("参数[%s]不合规", key))
}
} }
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment