Set method as first parameter of AddRoute function in Router interface

This commit is contained in:
danibix95
2021-11-23 23:19:52 +01:00
parent 715c554482
commit 3d21dece34
5 changed files with 6 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ type gorillaRouter struct {
router *mux.Router
}
func (r gorillaRouter) AddRoute(path string, method string, handler HandlerFunc) Route {
func (r gorillaRouter) AddRoute(method string, path string, handler HandlerFunc) Route {
return r.router.HandleFunc(path, handler).Methods(method)
}

View File

@@ -18,7 +18,7 @@ func TestGorillaMuxRouter(t *testing.T) {
})
t.Run("add new route", func(t *testing.T) {
route := ar.AddRoute("/foo", http.MethodGet, func(w http.ResponseWriter, req *http.Request) {
route := ar.AddRoute(http.MethodGet, "/foo", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
w.Write(nil)
})

View File

@@ -6,7 +6,7 @@ import "net/http"
type HandlerFunc func(w http.ResponseWriter, req *http.Request)
type Router interface {
AddRoute(path string, method string, handler HandlerFunc) Route
AddRoute(method string, path string, handler HandlerFunc) Route
}
type Route interface{}

View File

@@ -139,7 +139,7 @@ func (r Router) GenerateAndExposeSwagger() error {
if err != nil {
return fmt.Errorf("%w json marshal: %s", ErrGenerateSwagger, err)
}
r.router.AddRoute(r.jsonDocumentationPath, http.MethodGet, func(w http.ResponseWriter, req *http.Request) {
r.router.AddRoute(http.MethodGet, r.jsonDocumentationPath, func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(jsonSwagger)
@@ -149,7 +149,7 @@ func (r Router) GenerateAndExposeSwagger() error {
if err != nil {
return fmt.Errorf("%w yaml marshal: %s", ErrGenerateSwagger, err)
}
r.router.AddRoute(r.yamlDocumentationPath, http.MethodGet, func(w http.ResponseWriter, req *http.Request) {
r.router.AddRoute(http.MethodGet,r.yamlDocumentationPath, func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write(yamlSwagger)

View File

@@ -41,7 +41,7 @@ func (r Router) AddRawRoute(method string, routePath string, handler apirouter.H
r.swaggerSchema.AddOperation(pathWithPrefix, method, op)
// Handle, when content-type is json, the request/response marshalling? Maybe with a specific option.
return r.router.AddRoute(pathWithPrefix, method, handler), nil
return r.router.AddRoute(method, pathWithPrefix, handler), nil
}
// Content is the type of a content.