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.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 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) {