Skip to content

Commit c7caacd

Browse files
committed
fix router optional
1 parent 3564abb commit c7caacd

File tree

4 files changed

+179
-176
lines changed

4 files changed

+179
-176
lines changed

README.org

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@
233233
return "uuid"
234234
}
235235

236-
func (s *UUIDMatcher) Match(path string, count int, next bool) (int, bool) {
237-
if count > 0 {
236+
func (s *UUIDMatcher) Match(path string, index int, next bool) (int, bool) {
237+
if index > 0 {
238238
return 0, false
239239
}
240-
if len(path) < 18 {
240+
if len(path) < 18 || (!next && len(path) > 18) {
241241
return 0, false
242242
}
243243
_, err := uuid.Parse(path[:18])
@@ -251,7 +251,7 @@
251251
return &UUIDMatcher{}
252252
}
253253

254-
forest.RegisterURLParam("uuid", NewUUIDMatcher)
254+
forest.RegisterRule("uuid", NewUUIDMatcher)
255255

256256
router := forest.New()
257257
router.GET("/api/v1/user/{pk:uuid}", handler)

forest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (e *Forest) addRoute(host, method, path string) *Route {
154154
method: method,
155155
path: path,
156156
}
157-
root.insert(route)
157+
root.insert(route.Path(), route)
158158

159159
// maybe should check route.pnames can't be repeated
160160
if l := len(route.pnames); l > e.maxParam {

0 commit comments

Comments
 (0)