feat: update swagger embedded files (#66)
This commit is contained in:
@@ -30,7 +30,7 @@ And import following in your code:
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
import "github.com/swaggo/gin-swagger" // gin-swagger middleware
|
import "github.com/swaggo/gin-swagger" // gin-swagger middleware
|
||||||
import "github.com/swaggo/gin-swagger/swaggerFiles" // swagger embed files
|
import "github.com/swaggo/files" // swagger embed files
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/swaggo/files"
|
||||||
"github.com/swaggo/gin-swagger"
|
"github.com/swaggo/gin-swagger"
|
||||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
||||||
|
|
||||||
_ "./docs" // docs is generated by Swag CLI, you have to import it.
|
_ "./docs" // docs is generated by Swag CLI, you have to import it.
|
||||||
)
|
)
|
||||||
@@ -64,11 +64,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
r := gin.New()
|
r := gin.New()
|
||||||
|
|
||||||
config := &ginSwagger.Config{
|
url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition
|
||||||
URL: "http://localhost:8080/swagger/doc.json", //The url pointing to API definition
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
|
||||||
}
|
|
||||||
// use ginSwagger middleware to
|
|
||||||
r.GET("/swagger/*any", ginSwagger.CustomWrapHandler(config, swaggerFiles.Handler))
|
|
||||||
|
|
||||||
r.Run()
|
r.Run()
|
||||||
}
|
}
|
||||||
@@ -76,7 +73,7 @@ func main() {
|
|||||||
|
|
||||||
5. Run it, and browser to http://localhost:8080/swagger/index.html, you can see Swagger 2.0 Api documents.
|
5. Run it, and browser to http://localhost:8080/swagger/index.html, you can see Swagger 2.0 Api documents.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
6. If you want to disable swagger when some environment variable is set, use `DisablingWrapHandler`
|
6. If you want to disable swagger when some environment variable is set, use `DisablingWrapHandler`
|
||||||
|
|
||||||
@@ -87,8 +84,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/swaggo/files"
|
||||||
"github.com/swaggo/gin-swagger"
|
"github.com/swaggo/gin-swagger"
|
||||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
||||||
|
|
||||||
_ "./docs" // docs is generated by Swag CLI, you have to import it.
|
_ "./docs" // docs is generated by Swag CLI, you have to import it.
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/swaggo/files"
|
||||||
"github.com/swaggo/gin-swagger"
|
"github.com/swaggo/gin-swagger"
|
||||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
||||||
|
|
||||||
_ "github.com/swaggo/gin-swagger/example/basic/docs"
|
_ "github.com/swaggo/gin-swagger/example/basic/docs"
|
||||||
)
|
)
|
||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
r := gin.New()
|
r := gin.New()
|
||||||
|
|
||||||
url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") //The url pointing to API definition
|
url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition
|
||||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
|
||||||
|
|
||||||
r.Run()
|
r.Run()
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/gin-contrib/gzip"
|
"github.com/gin-contrib/gzip"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/swaggo/files"
|
||||||
"github.com/swaggo/gin-swagger"
|
"github.com/swaggo/gin-swagger"
|
||||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
||||||
|
|
||||||
_ "github.com/swaggo/gin-swagger/example/basic/docs"
|
_ "github.com/swaggo/gin-swagger/example/basic/docs"
|
||||||
)
|
)
|
||||||
@@ -28,7 +28,7 @@ func main() {
|
|||||||
|
|
||||||
r.Use(gzip.Gzip(gzip.BestSpeed))
|
r.Use(gzip.Gzip(gzip.BestSpeed))
|
||||||
|
|
||||||
url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") //The url pointing to API definition
|
url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition
|
||||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
|
||||||
|
|
||||||
r.Run()
|
r.Run()
|
||||||
|
|||||||
Reference in New Issue
Block a user