新增core模块核心库

This commit is contained in:
TsMask
2023-08-26 17:01:49 +08:00
parent 9a6684b257
commit 26b55965da
10 changed files with 614 additions and 0 deletions

29
lib/core/utils/ctx/ctx.go Normal file
View File

@@ -0,0 +1,29 @@
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
}