From 5f86296d29e96b0b665af0325c016f8d5b4e9d6d Mon Sep 17 00:00:00 2001 From: David Zingerman Date: Tue, 1 Sep 2020 10:31:24 +0300 Subject: [PATCH 1/2] fixed index out of range of the matches at swagger.go:71 --- swagger.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swagger.go b/swagger.go index bfd1ead..3813ef8 100644 --- a/swagger.go +++ b/swagger.go @@ -69,8 +69,11 @@ func Handler(configFns ...func(*Config)) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { matches := re.FindStringSubmatch(r.RequestURI) - path := matches[2] - prefix := matches[1] + var path, prefix string + if len(matches) > 2 { + path = matches[2] + prefix = matches[1] + } h := swaggerFiles.Handler h.Prefix = prefix From 0d32c8ad99f0fb99188da7cefa5280e61287656e Mon Sep 17 00:00:00 2001 From: David Zingerman Date: Tue, 1 Sep 2020 10:38:15 +0300 Subject: [PATCH 2/2] changed module name --- example/go-chi/main.go | 4 ++-- example/gorilla/main.go | 4 ++-- go.mod | 2 +- swagger_test.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example/go-chi/main.go b/example/go-chi/main.go index 80dc90c..8a84f72 100644 --- a/example/go-chi/main.go +++ b/example/go-chi/main.go @@ -4,9 +4,9 @@ import ( "log" "net/http" + httpSwagger "github.com/Dysar/http-swagger" + _ "github.com/Dysar/http-swagger/example/go-chi/docs" // docs is generated by Swag CLI, you have to import it. "github.com/go-chi/chi" - httpSwagger "github.com/swaggo/http-swagger" - _ "github.com/swaggo/http-swagger/example/go-chi/docs" // docs is generated by Swag CLI, you have to import it. ) // @title Swagger Example API diff --git a/example/gorilla/main.go b/example/gorilla/main.go index 6feddeb..b0f5deb 100644 --- a/example/gorilla/main.go +++ b/example/gorilla/main.go @@ -4,9 +4,9 @@ import ( "log" "net/http" + httpSwagger "github.com/Dysar/http-swagger" + _ "github.com/Dysar/http-swagger/example/gorilla/docs" // docs is generated by Swag CLI, you have to import it. "github.com/gorilla/mux" - httpSwagger "github.com/swaggo/http-swagger" - _ "github.com/swaggo/http-swagger/example/gorilla/docs" // docs is generated by Swag CLI, you have to import it. ) // @title Swagger Example API diff --git a/go.mod b/go.mod index 41dc335..9100584 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/swaggo/http-swagger +module github.com/Dysar/http-swagger go 1.13 diff --git a/swagger_test.go b/swagger_test.go index b3ac9be..90a7964 100644 --- a/swagger_test.go +++ b/swagger_test.go @@ -5,9 +5,9 @@ import ( "net/http/httptest" "testing" + _ "github.com/Dysar/http-swagger/example/go-chi/docs" "github.com/go-chi/chi" "github.com/stretchr/testify/assert" - _ "github.com/swaggo/http-swagger/example/go-chi/docs" ) func TestWrapHandler(t *testing.T) {