👷 Auto add '/' prefix for Group

pull/1089/head
Kiyon 2020-12-24 14:14:49 +08:00
parent 2604398cac
commit bdfad180f7
2 changed files with 8 additions and 0 deletions

View File

@ -211,6 +211,11 @@ func getGroupPath(prefix, path string) string {
if path == "/" { if path == "/" {
return prefix return prefix
} }
if path[0] != '/' {
path = "/" + path
}
return utils.TrimRight(prefix, '/') + path return utils.TrimRight(prefix, '/') + path
} }

View File

@ -155,6 +155,9 @@ func Test_Utils_getGroupPath(t *testing.T) {
res = getGroupPath("/v1/api/", "/") res = getGroupPath("/v1/api/", "/")
utils.AssertEqual(t, "/v1/api/", res) 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 // go test -v -run=^$ -bench=Benchmark_Utils_ -benchmem -count=3