diff options
| author | Eltrac <hi@guhub.cn> | 2025-12-03 15:36:29 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-12-03 15:36:29 +0800 |
| commit | f2103d4182acde938572c16753f8752c1f811fbf (patch) | |
| tree | 9653faea7dd4e742c2d65fb7f758f3ebf9239a67 /parser.go | |
| parent | 2ac34a23542c7c66427e7ca9bd33d14ba03c0dd7 (diff) | |
refactor: use vanilla URL.Query() instead of a custom parser
Since `parser.go` only exists for splitting paths and parsing query string at
the same time, it should be removed when parsing is no longer needed. Path
splitting is done by a helper function inside `router.go`.
Diffstat (limited to 'parser.go')
| -rw-r--r-- | parser.go | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/parser.go b/parser.go deleted file mode 100644 index 87b06d0..0000000 --- a/parser.go +++ /dev/null @@ -1,55 +0,0 @@ -package growel - -import ( - "fmt" - "strings" -) - -func ParsePath(path string) ([]string, map[string]string) { - var query_str string - path, query_str = extractQueryStr(path) - - parts := splitPath(path) - - if len(parts) == 0 { - return parts, map[string]string{} - } - - query := parseQueryStr(query_str) - - return parts, query -} - -func splitPath(path string) []string { - return strings.Split(strings.Trim(path, "/"), "/") -} - -func extractQueryStr(str string) (path string, querystr string) { - str_slice := strings.Split(str, "?") - leng := len(str_slice) - if leng > 2 { - fmt.Println("Error parsing path: multiple '?' found.") - // return anyway - } else if leng == 1 { - // no query string found - return str_slice[0], "" - } - return str_slice[0], str_slice[1] -} - -func parseQueryStr(str string) map[string]string { - query := make(map[string]string) - if str == "" { - return query - } - pairs := strings.Split(str, "&") - for _, pair := range pairs { - kv := strings.Split(pair, "=") - if len(kv) != 2 { - fmt.Println("Error parsing query string: invalid key-value pair.") - continue - } - query[kv[0]] = kv[1] - } - return query -} |
