Skip to content

Commit

Permalink
feat: update swagger embedded files (swaggo#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
easonlin404 authored Jul 5, 2019
1 parent 2d58c08 commit 08f4913
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ And import following in your code:

```go
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

```

Expand All @@ -41,8 +41,8 @@ package main

import (
"github.com/gin-gonic/gin"
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"

_ "./docs" // docs is generated by Swag CLI, you have to import it.
)
Expand All @@ -63,20 +63,17 @@ import (
// @BasePath /v2
func main() {
r := gin.New()

config := &ginSwagger.Config{
URL: "http://localhost:8080/swagger/doc.json", //The url pointing to API definition
}
// use ginSwagger middleware to
r.GET("/swagger/*any", ginSwagger.CustomWrapHandler(config, swaggerFiles.Handler))

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.Run()
}
```

5. Run it, and browser to http://localhost:8080/swagger/index.html, you can see Swagger 2.0 Api documents.

![swagger_index.html](https://user-images.githubusercontent.com/8943871/31943004-dd08a10e-b88c-11e7-9e77-19d2c759a586.png)
![swagger_index.html](https://user-images.githubusercontent.com/8943871/60704329-b7ab0680-9f36-11e9-9184-5c638c05e9c5.png)

6. If you want to disable swagger when some environment variable is set, use `DisablingWrapHandler`

Expand All @@ -87,9 +84,9 @@ package main

import (
"github.com/gin-gonic/gin"
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"


_ "./docs" // docs is generated by Swag CLI, you have to import it.
)

Expand Down
4 changes: 2 additions & 2 deletions example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"github.com/gin-gonic/gin"
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"

_ "github.com/swaggo/gin-swagger/example/basic/docs"
)
Expand All @@ -25,7 +25,7 @@ import (
func main() {
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.Run()
Expand Down
4 changes: 2 additions & 2 deletions example/gzipped/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"

_ "github.com/swaggo/gin-swagger/example/basic/docs"
)
Expand All @@ -28,7 +28,7 @@ func main() {

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.Run()
Expand Down

0 comments on commit 08f4913

Please sign in to comment.