Skip to content

Commit

Permalink
Merge pull request #1035 from HusterWan/zr/fix-api-version
Browse files Browse the repository at this point in the history
bugfix: restful api url should support both with or without version info
  • Loading branch information
allencloud authored Apr 3, 2018
2 parents 9f5f182 + 4690a00 commit 46c67ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apis/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func initRoute(s *Server) http.Handler {

// metrics
r.Path(versionMatcher + "/metrics").Methods(http.MethodGet).Handler(prometheus.Handler())
r.Path("/metrics").Methods(http.MethodGet).Handler(prometheus.Handler())

if s.Config.Debug {
profilerSetup(r)
Expand All @@ -83,6 +84,7 @@ func initRoute(s *Server) http.Handler {

func addRoute(r *mux.Router, mothod string, path string, f func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error) {
r.Path(versionMatcher + path).Methods(mothod).Handler(filter(f))
r.Path(path).Methods(mothod).Handler(filter(f))
}

func profilerSetup(mainRouter *mux.Router) {
Expand Down
3 changes: 2 additions & 1 deletion test/api_version_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (suite *APIVersionSuite) SetUpTest(c *check.C) {
}

// TestNoVersionParamsInURL test api url not contains version info.
// Pouch api url support with or without version info.
func (suite *APIVersionSuite) TestNoVersionParamsInURL(c *check.C) {
cname := "TestCreateURLNoVersionInfo"

Expand Down Expand Up @@ -55,5 +56,5 @@ func (suite *APIVersionSuite) TestNoVersionParamsInURL(c *check.C) {
resp, err := apiClient.HTTPCli.Do(req)
c.Assert(err, check.IsNil)

CheckRespStatus(c, resp, 404)
CheckRespStatus(c, resp, 201)
}

0 comments on commit 46c67ec

Please sign in to comment.