Skip to content

Commit f9a3e27

Browse files
authored
Merge pull request #13 from go-rs/develop
Develop
2 parents 4a59a71 + 68af856 commit f9a3e27

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type exception struct {
5353

5454
// Initialize an API with prefix value and return the API pointer
5555
func New(prefix string) *API {
56+
prefix = utils.TrimSuffix(prefix, "/")
5657
return &API{
5758
prefix: prefix,
5859
}

namespace.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package rest
66

7-
import "net/http"
7+
import (
8+
"github.com/go-rs/rest-api-framework/utils"
9+
"net/http"
10+
)
811

912
// Namespace is used to extend routes with a specific prefix
1013
type Namespace struct {
@@ -14,6 +17,7 @@ type Namespace struct {
1417

1518
// Set method is used to set prefix with API
1619
func (n *Namespace) Set(prefix string, api *API) {
20+
prefix = utils.TrimSuffix(prefix, "/")
1721
n.prefix = prefix
1822
n.api = api
1923
}

utils/url.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ func Exec(regex *regexp.Regexp, keys []string, uri []byte) (params map[string]st
7070

7171
return
7272
}
73+
74+
// Trim last occurrence of string
75+
func TrimSuffix(s, suffix string) string {
76+
if strings.HasSuffix(s, suffix) {
77+
s = s[:len(s)-len(suffix)]
78+
}
79+
return s
80+
}

0 commit comments

Comments
 (0)