Skip to content

Commit 522db3b

Browse files
committed
added additional mappings
1 parent 74617c7 commit 522db3b

File tree

5 files changed

+267
-54
lines changed

5 files changed

+267
-54
lines changed

coverage.out

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/GolangToolKits/grrt/reqRoute.go:165.13,167.3 1 1
4545
github.com/GolangToolKits/grrt/reqRoute.go:167.8,169.3 1 1
4646
github.com/GolangToolKits/grrt/reqRoute.go:170.2,170.12 1 1
4747
github.com/GolangToolKits/grrt/reqRoute.go:173.55,180.22 6 1
48-
github.com/GolangToolKits/grrt/reqRoute.go:180.22,181.31 1 1
49-
github.com/GolangToolKits/grrt/reqRoute.go:181.31,184.9 3 1
48+
github.com/GolangToolKits/grrt/reqRoute.go:180.22,181.46 1 1
49+
github.com/GolangToolKits/grrt/reqRoute.go:181.46,184.9 3 1
5050
github.com/GolangToolKits/grrt/reqRoute.go:185.9,185.21 1 1
5151
github.com/GolangToolKits/grrt/reqRoute.go:185.21,187.4 1 1
5252
github.com/GolangToolKits/grrt/reqRoute.go:188.3,188.31 1 1
@@ -133,21 +133,27 @@ github.com/GolangToolKits/grrt/reqRouter.go:166.55,170.28 4 1
133133
github.com/GolangToolKits/grrt/reqRouter.go:170.28,172.3 1 1
134134
github.com/GolangToolKits/grrt/reqRouter.go:173.2,173.30 1 1
135135
github.com/GolangToolKits/grrt/reqRouter.go:176.49,180.2 3 1
136-
github.com/GolangToolKits/grrt/reqRouter.go:182.70,190.23 7 1
137-
github.com/GolangToolKits/grrt/reqRouter.go:190.23,191.13 1 1
138-
github.com/GolangToolKits/grrt/reqRouter.go:191.13,192.12 1 1
139-
github.com/GolangToolKits/grrt/reqRouter.go:193.9,193.19 1 1
140-
github.com/GolangToolKits/grrt/reqRouter.go:193.19,194.9 1 1
141-
github.com/GolangToolKits/grrt/reqRouter.go:196.3,198.17 3 1
142-
github.com/GolangToolKits/grrt/reqRouter.go:198.17,199.28 1 1
143-
github.com/GolangToolKits/grrt/reqRouter.go:199.28,200.38 1 1
144-
github.com/GolangToolKits/grrt/reqRouter.go:200.38,204.11 4 1
145-
github.com/GolangToolKits/grrt/reqRouter.go:207.9,209.4 1 1
146-
github.com/GolangToolKits/grrt/reqRouter.go:211.2,211.19 1 1
147-
github.com/GolangToolKits/grrt/reqRouter.go:214.96,216.36 2 1
148-
github.com/GolangToolKits/grrt/reqRouter.go:216.36,217.32 1 1
149-
github.com/GolangToolKits/grrt/reqRouter.go:217.32,219.4 1 1
150-
github.com/GolangToolKits/grrt/reqRouter.go:221.2,222.27 2 1
136+
github.com/GolangToolKits/grrt/reqRouter.go:182.70,188.33 5 1
137+
github.com/GolangToolKits/grrt/reqRouter.go:188.33,190.3 1 1
138+
github.com/GolangToolKits/grrt/reqRouter.go:190.8,192.3 1 1
139+
github.com/GolangToolKits/grrt/reqRouter.go:193.2,197.23 4 1
140+
github.com/GolangToolKits/grrt/reqRouter.go:197.23,200.12 1 1
141+
github.com/GolangToolKits/grrt/reqRouter.go:200.12,201.9 1 1
142+
github.com/GolangToolKits/grrt/reqRouter.go:209.3,209.24 1 1
143+
github.com/GolangToolKits/grrt/reqRouter.go:209.24,211.4 1 1
144+
github.com/GolangToolKits/grrt/reqRouter.go:211.9,213.4 1 1
145+
github.com/GolangToolKits/grrt/reqRouter.go:215.3,216.17 2 1
146+
github.com/GolangToolKits/grrt/reqRouter.go:216.17,217.28 1 1
147+
github.com/GolangToolKits/grrt/reqRouter.go:217.28,218.38 1 1
148+
github.com/GolangToolKits/grrt/reqRouter.go:218.38,222.41 4 1
149+
github.com/GolangToolKits/grrt/reqRouter.go:222.41,224.7 1 1
150+
github.com/GolangToolKits/grrt/reqRouter.go:225.6,225.11 1 1
151+
github.com/GolangToolKits/grrt/reqRouter.go:228.9,230.4 1 1
152+
github.com/GolangToolKits/grrt/reqRouter.go:232.2,232.19 1 1
153+
github.com/GolangToolKits/grrt/reqRouter.go:235.96,237.36 2 1
154+
github.com/GolangToolKits/grrt/reqRouter.go:237.36,238.32 1 1
155+
github.com/GolangToolKits/grrt/reqRouter.go:238.32,240.4 1 1
156+
github.com/GolangToolKits/grrt/reqRouter.go:242.2,243.27 2 1
151157
github.com/GolangToolKits/grrt/router.go:29.25,34.2 4 1
152158
github.com/GolangToolKits/grrt/router.go:37.46,39.49 2 1
153159
github.com/GolangToolKits/grrt/router.go:39.49,41.3 1 1

reqRoute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (t *ReqRoute) chechCurlyPlacement(p string) bool {
178178
var lastOc int = 0
179179
var lastCc int = 0
180180
for i, c := range p {
181-
if c == oc && i == lastOc+1 {
181+
if c == oc && i == lastOc+1 && lastOc != 0 {
182182
t.printError(p, "Route can not have {{")
183183
rtn = false
184184
break

reqRoute_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ func TestReqRoute_chechPath(t *testing.T) {
3939
},
4040
want: false,
4141
},
42+
{
43+
name: "url match success",
44+
args: args{
45+
p: "/",
46+
},
47+
want: true,
48+
},
49+
{
50+
name: "url match success",
51+
args: args{
52+
p: "/{parm1}",
53+
},
54+
want: true,
55+
},
4256
}
4357
for _, tt := range tests {
4458
t.Run(tt.name, func(t *testing.T) {
@@ -222,6 +236,13 @@ func TestReqRoute_chechCurlyPlacement(t *testing.T) {
222236
},
223237
want: false,
224238
},
239+
{
240+
name: "test 3 fail",
241+
args: args{
242+
p: "/{parm1}",
243+
},
244+
want: true,
245+
},
225246
}
226247
for _, tt := range tests {
227248
t.Run(tt.name, func(t *testing.T) {
@@ -386,6 +407,36 @@ func TestReqRoute_Path(t *testing.T) {
386407
pathVarNames: &[]string{},
387408
},
388409
},
410+
{
411+
name: "test 4 ",
412+
args: args{
413+
p: "/",
414+
},
415+
fields: fields{
416+
pathVarNames: &[]string{},
417+
},
418+
want: &ReqRoute{
419+
path: "/",
420+
active: true,
421+
pathVarsUsed: true,
422+
pathVarNames: &[]string{},
423+
},
424+
},
425+
{
426+
name: "test 5 ",
427+
args: args{
428+
p: "/{param1}",
429+
},
430+
fields: fields{
431+
pathVarNames: &[]string{},
432+
},
433+
want: &ReqRoute{
434+
path: "/",
435+
active: true,
436+
pathVarsUsed: true,
437+
pathVarNames: &[]string{"param1"},
438+
},
439+
},
389440
}
390441
for _, tt := range tests {
391442
t.Run(tt.name, func(t *testing.T) {

reqRouter.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,45 @@ func (t *ReqRouter) findRouteAndVars(path string) (Route, *[]string) {
183183
var rnt Route
184184
sp := strings.Split(path, "/")
185185
var vars []string
186-
var vcnt = len(sp) - 2
186+
// var vcnt = len(sp) - 2
187+
var vl int
188+
if len(sp) == 2 && sp[1] == "" {
189+
vl = len(sp) - 2
190+
} else {
191+
vl = len(sp) - 1
192+
}
193+
var vcnt = vl
187194
//log.Println("sp:", sp)
188195
var found = false
189196
var searchPath = ""
190197
for i, p := range sp {
191-
if i == 0 {
192-
continue
193-
} else if found {
198+
//if i == 0 {
199+
//continue
200+
if found {
194201
break
195202
}
196-
searchPath += "/" + p
203+
// if i == 0 {
204+
// continue
205+
// } else if found {
206+
// break
207+
// }
208+
// searchPath += "/" + p
209+
if searchPath == "/" {
210+
searchPath += p
211+
} else {
212+
searchPath += "/" + p
213+
}
214+
// searchPath += "/" + p
197215
rts := t.namedRoutes[searchPath]
198216
if rts != nil {
199217
for _, rt := range *rts {
200218
if rt.GetPathVarsCount() == vcnt {
201219
rnt = rt
202220
found = true
203221
vars = sp[i+1:]
222+
if len(vars) == 1 && vars[0] == "" {
223+
vars = []string{}
224+
}
204225
break
205226
}
206227
}

0 commit comments

Comments
 (0)