From 8e5109d3fd087af053276b068bde53b275b6f048 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 7 Jan 2024 18:24:00 +0800 Subject: [PATCH] Add TypesQueryParam function to handle get Template request --- sui/api/process.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sui/api/process.go b/sui/api/process.go index d1ae312a..a778214f 100644 --- a/sui/api/process.go +++ b/sui/api/process.go @@ -11,6 +11,7 @@ import ( "github.com/gin-gonic/gin" jsoniter "github.com/json-iterator/go" "github.com/yaoapp/gou/process" + "github.com/yaoapp/gou/types" "github.com/yaoapp/kun/exception" "github.com/yaoapp/yao/sui/core" ) @@ -57,9 +58,48 @@ func init() { "build.all": BuildAll, "build.page": BuildPage, + + // Will be deprecated or change in the future + "types.QueryParam": TypesQueryParam, }) } +// TypesQueryParam handle the get Template request +func TypesQueryParam(process *process.Process) interface{} { + process.ValidateArgNums(1) + switch v := process.Args[0].(type) { + + case url.Values: + return types.URLToQueryParam(v) + + case map[string][]string: + return types.URLToQueryParam(v) + + case map[string]interface{}: + values := url.Values{} + for key, value := range v { + switch val := value.(type) { + case []string: + for _, v := range val { + values.Add(key, v) + } + + case []interface{}: + for _, v := range val { + values.Add(key, fmt.Sprintf("%v", v)) + } + + default: + values.Set(key, fmt.Sprintf("%v", value)) + } + } + return types.URLToQueryParam(values) + } + + v, _ := types.AnyToQueryParam(process.Args[0]) + return v +} + // Setting handle the get Template request func Setting(process *process.Process) interface{} { sui := get(process)