File tree 3 files changed +13
-14
lines changed
3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change 1
1
module github.com/dpouris/goster
2
2
3
- go 1.18
3
+ go 1.21
Original file line number Diff line number Diff line change @@ -36,24 +36,26 @@ func (p *Path) Get(id string) (value string, exists bool) {
36
36
}
37
37
38
38
// Pass in a `url` and see if there're parameters in it
39
- //
39
+ //
40
40
// If there're, ParseUrl will construct a Params struct and populate Meta.Query.Params
41
- //
41
+ //
42
42
// If there aren't any, ParseUrl will return the error that occurred
43
- //
43
+ //
44
44
// The `url` string reference that is passed in will have the parameters stripped in either case
45
45
func (m * Meta ) ParseUrl (url * string ) (err error ) {
46
46
paramValues := make (map [string ]string , 0 )
47
47
paramPattern := regexp .MustCompile (`\?.+(\/)?` )
48
- pathPattern := regexp .MustCompile (`^(\/\w+)+(\?)?` )
48
+ pathPattern := regexp .MustCompile (`^(\/\w+)+(\/)*(\ ?)?` )
49
49
defer func () {
50
50
m .Query = Params {
51
51
values : paramValues ,
52
52
}
53
- }()
54
-
55
- defer func () {
56
- * url = strings .Trim (pathPattern .FindString (* url ), "?" )
53
+ matchedStr := pathPattern .FindString (* url )
54
+ if len (matchedStr ) != 0 {
55
+ * url = matchedStr
56
+ }
57
+ * url = strings .Trim (* url , "?" )
58
+ cleanPath (url )
57
59
}()
58
60
59
61
params := paramPattern .FindString (* url )
Original file line number Diff line number Diff line change @@ -12,18 +12,15 @@ func DefaultHeader(c *Ctx) {
12
12
}
13
13
14
14
func cleanPath (path * string ) {
15
- if * path == "/" {
16
- * path = ""
15
+ if len (* path ) == 0 {
17
16
return
18
17
}
19
18
20
19
if (* path )[0 ] != '/' {
21
20
* path = "/" + * path
22
21
}
23
22
24
- * path = strings .TrimRightFunc (* path , func (r rune ) bool {
25
- return r == '/'
26
- })
23
+ * path = strings .TrimSuffix (* path , "/" )
27
24
}
28
25
29
26
func cleanEmptyBytes (b * []byte ) {
You can’t perform that action at this time.
0 commit comments