Skip to content

Commit 1c9920c

Browse files
authored
Merge pull request #183 from boisjacques/182-restconf
Added restconf prefix and test cases
2 parents 5fc6d79 + 93443cc commit 1c9920c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

middleware/denco/router.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const (
2020
// SeparatorCharacter separates path segments.
2121
SeparatorCharacter = '/'
2222

23+
// PathParamCharacter indicates a RESTCONF path param
24+
PathParamCharacter = '='
25+
2326
// MaxSize is max size of records and internal slice.
2427
MaxSize = (1 << 22) - 1
2528
)
@@ -426,8 +429,9 @@ func makeRecords(srcs []Record) (statics, params []*record) {
426429
termChar := string(TerminationCharacter)
427430
paramPrefix := string(SeparatorCharacter) + string(ParamCharacter)
428431
wildcardPrefix := string(SeparatorCharacter) + string(WildcardCharacter)
432+
restconfPrefix := string(PathParamCharacter) + string(ParamCharacter)
429433
for _, r := range srcs {
430-
if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) {
434+
if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) ||strings.Contains(r.Key, restconfPrefix){
431435
r.Key += termChar
432436
params = append(params, &record{Record: r})
433437
} else {

middleware/denco/router_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func routes() []denco.Record {
2626
{"/:year/:month/:day", "testroute8"},
2727
{"/user/:id", "testroute9"},
2828
{"/a/to/b/:param/*routepath", "testroute10"},
29+
{"/path/with/key=:value", "testroute14"},
2930
}
3031
}
3132

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

0 commit comments

Comments
 (0)