From bdfad180f75c6818cc8743513dcd570069146cdc Mon Sep 17 00:00:00 2001 From: Kiyon Date: Thu, 24 Dec 2020 14:14:49 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Auto=20add=20'/'=20prefix=20for?= =?UTF-8?q?=20Group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helpers.go | 5 +++++ helpers_test.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/helpers.go b/helpers.go index 6d6e49be..77907e6a 100644 --- a/helpers.go +++ b/helpers.go @@ -211,6 +211,11 @@ func getGroupPath(prefix, path string) string { if path == "/" { return prefix } + + if path[0] != '/' { + path = "/" + path + } + return utils.TrimRight(prefix, '/') + path } diff --git a/helpers_test.go b/helpers_test.go index b0d90aa6..45a34097 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -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