Skip to content

Commit

Permalink
added additional mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Mar 20, 2023
1 parent 74617c7 commit 522db3b
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 54 deletions.
40 changes: 23 additions & 17 deletions coverage.out
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ github.com/GolangToolKits/grrt/reqRoute.go:165.13,167.3 1 1
github.com/GolangToolKits/grrt/reqRoute.go:167.8,169.3 1 1
github.com/GolangToolKits/grrt/reqRoute.go:170.2,170.12 1 1
github.com/GolangToolKits/grrt/reqRoute.go:173.55,180.22 6 1
github.com/GolangToolKits/grrt/reqRoute.go:180.22,181.31 1 1
github.com/GolangToolKits/grrt/reqRoute.go:181.31,184.9 3 1
github.com/GolangToolKits/grrt/reqRoute.go:180.22,181.46 1 1
github.com/GolangToolKits/grrt/reqRoute.go:181.46,184.9 3 1
github.com/GolangToolKits/grrt/reqRoute.go:185.9,185.21 1 1
github.com/GolangToolKits/grrt/reqRoute.go:185.21,187.4 1 1
github.com/GolangToolKits/grrt/reqRoute.go:188.3,188.31 1 1
Expand Down Expand Up @@ -133,21 +133,27 @@ github.com/GolangToolKits/grrt/reqRouter.go:166.55,170.28 4 1
github.com/GolangToolKits/grrt/reqRouter.go:170.28,172.3 1 1
github.com/GolangToolKits/grrt/reqRouter.go:173.2,173.30 1 1
github.com/GolangToolKits/grrt/reqRouter.go:176.49,180.2 3 1
github.com/GolangToolKits/grrt/reqRouter.go:182.70,190.23 7 1
github.com/GolangToolKits/grrt/reqRouter.go:190.23,191.13 1 1
github.com/GolangToolKits/grrt/reqRouter.go:191.13,192.12 1 1
github.com/GolangToolKits/grrt/reqRouter.go:193.9,193.19 1 1
github.com/GolangToolKits/grrt/reqRouter.go:193.19,194.9 1 1
github.com/GolangToolKits/grrt/reqRouter.go:196.3,198.17 3 1
github.com/GolangToolKits/grrt/reqRouter.go:198.17,199.28 1 1
github.com/GolangToolKits/grrt/reqRouter.go:199.28,200.38 1 1
github.com/GolangToolKits/grrt/reqRouter.go:200.38,204.11 4 1
github.com/GolangToolKits/grrt/reqRouter.go:207.9,209.4 1 1
github.com/GolangToolKits/grrt/reqRouter.go:211.2,211.19 1 1
github.com/GolangToolKits/grrt/reqRouter.go:214.96,216.36 2 1
github.com/GolangToolKits/grrt/reqRouter.go:216.36,217.32 1 1
github.com/GolangToolKits/grrt/reqRouter.go:217.32,219.4 1 1
github.com/GolangToolKits/grrt/reqRouter.go:221.2,222.27 2 1
github.com/GolangToolKits/grrt/reqRouter.go:182.70,188.33 5 1
github.com/GolangToolKits/grrt/reqRouter.go:188.33,190.3 1 1
github.com/GolangToolKits/grrt/reqRouter.go:190.8,192.3 1 1
github.com/GolangToolKits/grrt/reqRouter.go:193.2,197.23 4 1
github.com/GolangToolKits/grrt/reqRouter.go:197.23,200.12 1 1
github.com/GolangToolKits/grrt/reqRouter.go:200.12,201.9 1 1
github.com/GolangToolKits/grrt/reqRouter.go:209.3,209.24 1 1
github.com/GolangToolKits/grrt/reqRouter.go:209.24,211.4 1 1
github.com/GolangToolKits/grrt/reqRouter.go:211.9,213.4 1 1
github.com/GolangToolKits/grrt/reqRouter.go:215.3,216.17 2 1
github.com/GolangToolKits/grrt/reqRouter.go:216.17,217.28 1 1
github.com/GolangToolKits/grrt/reqRouter.go:217.28,218.38 1 1
github.com/GolangToolKits/grrt/reqRouter.go:218.38,222.41 4 1
github.com/GolangToolKits/grrt/reqRouter.go:222.41,224.7 1 1
github.com/GolangToolKits/grrt/reqRouter.go:225.6,225.11 1 1
github.com/GolangToolKits/grrt/reqRouter.go:228.9,230.4 1 1
github.com/GolangToolKits/grrt/reqRouter.go:232.2,232.19 1 1
github.com/GolangToolKits/grrt/reqRouter.go:235.96,237.36 2 1
github.com/GolangToolKits/grrt/reqRouter.go:237.36,238.32 1 1
github.com/GolangToolKits/grrt/reqRouter.go:238.32,240.4 1 1
github.com/GolangToolKits/grrt/reqRouter.go:242.2,243.27 2 1
github.com/GolangToolKits/grrt/router.go:29.25,34.2 4 1
github.com/GolangToolKits/grrt/router.go:37.46,39.49 2 1
github.com/GolangToolKits/grrt/router.go:39.49,41.3 1 1
Expand Down
2 changes: 1 addition & 1 deletion reqRoute.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (t *ReqRoute) chechCurlyPlacement(p string) bool {
var lastOc int = 0
var lastCc int = 0
for i, c := range p {
if c == oc && i == lastOc+1 {
if c == oc && i == lastOc+1 && lastOc != 0 {
t.printError(p, "Route can not have {{")
rtn = false
break
Expand Down
51 changes: 51 additions & 0 deletions reqRoute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ func TestReqRoute_chechPath(t *testing.T) {
},
want: false,
},
{
name: "url match success",
args: args{
p: "/",
},
want: true,
},
{
name: "url match success",
args: args{
p: "/{parm1}",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -222,6 +236,13 @@ func TestReqRoute_chechCurlyPlacement(t *testing.T) {
},
want: false,
},
{
name: "test 3 fail",
args: args{
p: "/{parm1}",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -386,6 +407,36 @@ func TestReqRoute_Path(t *testing.T) {
pathVarNames: &[]string{},
},
},
{
name: "test 4 ",
args: args{
p: "/",
},
fields: fields{
pathVarNames: &[]string{},
},
want: &ReqRoute{
path: "/",
active: true,
pathVarsUsed: true,
pathVarNames: &[]string{},
},
},
{
name: "test 5 ",
args: args{
p: "/{param1}",
},
fields: fields{
pathVarNames: &[]string{},
},
want: &ReqRoute{
path: "/",
active: true,
pathVarsUsed: true,
pathVarNames: &[]string{"param1"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
31 changes: 26 additions & 5 deletions reqRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,45 @@ func (t *ReqRouter) findRouteAndVars(path string) (Route, *[]string) {
var rnt Route
sp := strings.Split(path, "/")
var vars []string
var vcnt = len(sp) - 2
// var vcnt = len(sp) - 2
var vl int
if len(sp) == 2 && sp[1] == "" {
vl = len(sp) - 2
} else {
vl = len(sp) - 1
}
var vcnt = vl
//log.Println("sp:", sp)
var found = false
var searchPath = ""
for i, p := range sp {
if i == 0 {
continue
} else if found {
//if i == 0 {
//continue
if found {
break
}
searchPath += "/" + p
// if i == 0 {
// continue
// } else if found {
// break
// }
// searchPath += "/" + p
if searchPath == "/" {
searchPath += p
} else {
searchPath += "/" + p
}
// searchPath += "/" + p
rts := t.namedRoutes[searchPath]
if rts != nil {
for _, rt := range *rts {
if rt.GetPathVarsCount() == vcnt {
rnt = rt
found = true
vars = sp[i+1:]
if len(vars) == 1 && vars[0] == "" {
vars = []string{}
}
break
}
}
Expand Down
Loading

0 comments on commit 522db3b

Please sign in to comment.