Skip to content

Commit b194975

Browse files
committed
Added fix for instance of Echo that have a prefix (created with Group() method). The URI() method should return prefix plus the calculated string.
1 parent eee38a6 commit b194975

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

echo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (e *Echo) URI(h Handler, params ...string) string {
251251
}
252252
}
253253
}
254-
return uri.String()
254+
return e.prefix + uri.String()
255255
}
256256

257257
// URL is an alias for URI

echo_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,16 @@ func TestEchoURL(t *testing.T) {
239239
static := func(*Context) {}
240240
getUser := func(*Context) {}
241241
getFile := func(*Context) {}
242+
getGroups := func(*Context) {}
243+
getGroup := func(*Context) {}
244+
242245
e.Get("/static/file", static)
243246
e.Get("/users/:id", getUser)
244247
e.Get("/users/:uid/files/:fid", getFile)
245248

249+
eg := e.Group("/groups")
250+
eg.Get("/:id", getGroup)
251+
246252
if e.URL(static) != "/static/file" {
247253
t.Error("uri should be /static/file")
248254
}
@@ -261,6 +267,18 @@ func TestEchoURL(t *testing.T) {
261267
if e.URI(getFile, "1", "1") != "/users/1/files/1" {
262268
t.Error("uri should be /users/1/files/1")
263269
}
270+
if e.URI(getGroups) != "/groups" {
271+
t.Error("uri should be /groups")
272+
}
273+
if e.URI(getGroup, "1") != "/groups/1" {
274+
t.Error("uri should be /groups/1")
275+
}
276+
if eg.URI(getGroups) != "/groups" {
277+
t.Error("uri should be /groups")
278+
}
279+
if eg.URI(getGroup, "1") != "/groups/1" {
280+
t.Error("uri should be /groups/1")
281+
}
264282
}
265283

266284
func TestEchoNotFound(t *testing.T) {

0 commit comments

Comments
 (0)