Files
be.ems/lib/core/utils/ctx/ctx.go
2023-08-26 17:01:49 +08:00

30 lines
572 B
Go

package ctx
import (
"encoding/json"
"io"
"net/http"
"ems.agt/lib/global"
)
// QueryMap 查询参数转换Map
func QueryMap(r *http.Request) map[string]any {
queryValues := r.URL.Query()
queryParams := make(map[string]any)
for key, values := range queryValues {
queryParams[key] = values[0]
}
return queryParams
}
// 读取json请求结构团体
func ShouldBindJSON(r *http.Request, args any) error {
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
if err != nil {
return err
}
err = json.Unmarshal(body, args)
return err
}