Commit 4cd0b18a by zhengqiuyun86

go升级,泛型使用

parent 4b8063fb
......@@ -2,16 +2,25 @@ package util
import (
"bytes"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"github.com/gin-gonic/gin"
"io"
"net/http"
"strings"
)
func Param[T any](c *gin.Context, key string) *T {
if val, ok := c.Get(key); ok && val != nil {
i, _ := val.(T)
return &i
func Param[T any](c *gin.Context, key string) T {
val, ok := c.Get(key)
if ok {
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
}
......
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