Skip to content

Commit

Permalink
Merge pull request #183 from boisjacques/182-restconf
Browse files Browse the repository at this point in the history
Added restconf prefix and test cases
  • Loading branch information
casualjim committed Aug 26, 2020
2 parents 5fc6d79 + 93443cc commit 1c9920c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion middleware/denco/router.go
Expand Up @@ -20,6 +20,9 @@ const (
// SeparatorCharacter separates path segments.
SeparatorCharacter = '/'

// PathParamCharacter indicates a RESTCONF path param
PathParamCharacter = '='

// MaxSize is max size of records and internal slice.
MaxSize = (1 << 22) - 1
)
Expand Down Expand Up @@ -426,8 +429,9 @@ func makeRecords(srcs []Record) (statics, params []*record) {
termChar := string(TerminationCharacter)
paramPrefix := string(SeparatorCharacter) + string(ParamCharacter)
wildcardPrefix := string(SeparatorCharacter) + string(WildcardCharacter)
restconfPrefix := string(PathParamCharacter) + string(ParamCharacter)
for _, r := range srcs {
if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) {
if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) ||strings.Contains(r.Key, restconfPrefix){
r.Key += termChar
params = append(params, &record{Record: r})
} else {
Expand Down
2 changes: 2 additions & 0 deletions middleware/denco/router_test.go
Expand Up @@ -26,6 +26,7 @@ func routes() []denco.Record {
{"/:year/:month/:day", "testroute8"},
{"/user/:id", "testroute9"},
{"/a/to/b/:param/*routepath", "testroute10"},
{"/path/with/key=:value", "testroute14"},
}
}

Expand Down Expand Up @@ -211,6 +212,7 @@ func TestRouter_Lookup(t *testing.T) {
{"/user/777", "testroute9", []denco.Param{{"id", "777"}}, true},
{"/a/to/b/p1/some/wildcard/params", "testroute10", []denco.Param{{"param", "p1"}, {"routepath", "some/wildcard/params"}}, true},
{"/missing", nil, nil, false},
{"/path/with/key=value", "testroute14", []denco.Param{{"value", "value"}}, true},
}
runLookupTest(t, routes(), testcases)

Expand Down

0 comments on commit 1c9920c

Please sign in to comment.