Skip to content

Commit f0de896

Browse files
committed
improved query handling
1 parent 957dcd8 commit f0de896

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

utils/query/query.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func tryParseInt(str string) (int, bool) {
4444
return 0, false
4545
}
4646

47-
func ParseTypedQuery(values []string) interface{} {
47+
func ParseTypedQueryValues(values []string) interface{} {
4848
var result interface{}
4949

5050
raw := values[0]
@@ -80,3 +80,21 @@ func ParseTypedQuery(values []string) interface{} {
8080

8181
return result
8282
}
83+
84+
func ParseTypedQuery(query string, matchPrefix string) (map[string]interface{}) {
85+
addedData := map[string]interface{}{}
86+
87+
queryData := ParseRawQuery(query)
88+
89+
for key, value := range queryData {
90+
keyWithoutPrefix, match := strings.CutPrefix(key, matchPrefix)
91+
92+
if match {
93+
newValue := ParseTypedQueryValues(value)
94+
95+
addedData[keyWithoutPrefix] = newValue
96+
}
97+
}
98+
99+
return addedData
100+
}

utils/request/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func GetFormData(body []byte) (map[string]interface{}, error) {
7676
}
7777

7878
for key, value := range queryData {
79-
data[key] = query.ParseTypedQuery(value)
79+
data[key] = query.ParseTypedQueryValues(value)
8080
}
8181

8282
return data, nil

0 commit comments

Comments
 (0)