fix: mux上下文工具ctx

This commit is contained in:
TsMask
2024-06-15 16:36:47 +08:00
parent f930f5bde2
commit 09b4dbb321
2 changed files with 5 additions and 5 deletions

View File

@@ -17,8 +17,8 @@ import (
"golang.org/x/text/language"
)
// Param 地址栏参数{id}
func Param(r *http.Request, key string) string {
// GetParam 地址栏参数{id}
func GetParam(r *http.Request, key string) string {
vars := mux.Vars(r)
v, ok := vars[key]
if ok {
@@ -47,7 +47,7 @@ func QueryMap(r *http.Request) map[string]any {
return queryParams
}
// ShouldBindQuery 查询参数读取json请求结构团体
// ShouldBindQuery 查询参数读取json请求结构团体 &xxx
func ShouldBindQuery(r *http.Request, args any) error {
queryParams := QueryMap(r)
body, err := json.Marshal(queryParams)
@@ -57,7 +57,7 @@ func ShouldBindQuery(r *http.Request, args any) error {
return json.Unmarshal(body, args)
}
// 读取json请求结构团体
// ShouldBindJSON 读取json请求结构团体 &xxx
func ShouldBindJSON(r *http.Request, args any) error {
body, err := io.ReadAll(io.LimitReader(r.Body, 1<<20)) // 设置较大的长度,例如 1<<20 (1MB)
if err != nil {

View File

@@ -36,7 +36,7 @@ func LogMML(next http.Handler) http.Handler {
// 收尾存入数据库的参数
mmlCmd := bodyArgs["mml"].([]any)[0]
ipAddr := strings.Split(r.RemoteAddr, ":")[0]
neType := ctx.Param(r, "elementTypeValue")
neType := ctx.GetParam(r, "elementTypeValue")
neId := ctx.GetQuery(r, "ne_id")
timeStr := date.ParseDateToStr(time.Now(), date.YYYY_MM_DD_HH_MM_SS)