mirror of
https://github.com/davidebianchi/gswagger.git
synced 2026-06-12 14:04:14 -04:00
Set method as first parameter of AddRoute function in Router interface
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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{}
|
||||
|
||||
4
main.go
4
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)
|
||||
|
||||
2
route.go
2
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.
|
||||
|
||||
Reference in New Issue
Block a user