From 3d21dece34be2fb0d5ea00efb58a336ab2a426ed Mon Sep 17 00:00:00 2001 From: danibix95 Date: Tue, 23 Nov 2021 23:19:52 +0100 Subject: [PATCH] Set method as first parameter of AddRoute function in Router interface --- apirouter/gorilla.go | 2 +- apirouter/gorilla_test.go | 2 +- apirouter/router.go | 2 +- main.go | 4 ++-- route.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apirouter/gorilla.go b/apirouter/gorilla.go index aadb969..a6eaf6d 100644 --- a/apirouter/gorilla.go +++ b/apirouter/gorilla.go @@ -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) } diff --git a/apirouter/gorilla_test.go b/apirouter/gorilla_test.go index d6eeb80..975e993 100644 --- a/apirouter/gorilla_test.go +++ b/apirouter/gorilla_test.go @@ -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) }) diff --git a/apirouter/router.go b/apirouter/router.go index a43e1b4..8721ece 100644 --- a/apirouter/router.go +++ b/apirouter/router.go @@ -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{} diff --git a/main.go b/main.go index 95e2104..dd9fbef 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/route.go b/route.go index 36652aa..a264ff6 100644 --- a/route.go +++ b/route.go @@ -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.