Skip to content

Commit

Permalink
Merge pull request #1089 from kiyonlin/prefix-group-path
Browse files Browse the repository at this point in the history
👷 Auto add '/' prefix for Group
  • Loading branch information
Fenny authored Dec 28, 2020
2 parents d12ec4f + bdfad18 commit 6f31b5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ func getGroupPath(prefix, path string) string {
if path == "/" {
return prefix
}

if path[0] != '/' {
path = "/" + path
}

return utils.TrimRight(prefix, '/') + path
}

Expand Down
3 changes: 3 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func Test_Utils_getGroupPath(t *testing.T) {

res = getGroupPath("/v1/api/", "/")
utils.AssertEqual(t, "/v1/api/", res)

res = getGroupPath("/v1/api", "group")
utils.AssertEqual(t, "/v1/api/group", res)
}

// go test -v -run=^$ -bench=Benchmark_Utils_ -benchmem -count=3
Expand Down

0 comments on commit 6f31b5a

Please sign in to comment.