Update README.md
This commit is contained in:
parent
f677d2b131
commit
ee961b2c60
27
README.md
27
README.md
|
|
@ -10,28 +10,21 @@ gin middleware to automatically generate RESTful API documentation with Swagger
|
|||
## Usage
|
||||
|
||||
### Start using it
|
||||
1. Add comments to your API source code, [see Declarative Comments Format](#declarative-comments-format)
|
||||
2. Download Swag for Go by using:
|
||||
1. Add comments to your API source code, [See Declarative Comments Format](https://github.com/swag-gonic/swag#declarative-comments-format).
|
||||
2. Download [Swag](https://github.com/swag-gonic/swag) for Go by using:
|
||||
```sh
|
||||
$ go get -u github.com/swag-gonic/swag
|
||||
```
|
||||
3. Run the Swag in your Go project root folder which contains `main.go` file, Swag will parse your comments and generate required files(`docs` folder and `docs/doc.go`)
|
||||
|
||||
3. Run the [Swag](https://github.com/swag-gonic/swag) in your Go project root folder which contains `main.go` file, [Swag](https://github.com/swag-gonic/swag) will parse comments and generate required files(`docs` folder and `docs/doc.go`).
|
||||
```sh
|
||||
$ swag init
|
||||
```
|
||||
3.
|
||||
```
|
||||
|
||||
```sh
|
||||
$ go get github.com/swag-gonic/gin-swagger
|
||||
```
|
||||
|
||||
Import it in your code:
|
||||
4.Import following in your code:
|
||||
|
||||
```go
|
||||
import "github.com/gin-gonic/gin"
|
||||
import "github.com/swag-gonic/gin-swagger"
|
||||
import "github.com/swag-gonic/gin-swagger/swaggerFiles"
|
||||
import "github.com/swag-gonic/gin-swagger" // gin-swagger middleware
|
||||
import "github.com/swag-gonic/gin-swagger/swaggerFiles" // swagger embed files
|
||||
|
||||
```
|
||||
|
||||
|
|
@ -45,7 +38,7 @@ import (
|
|||
"github.com/swag-gonic/gin-swagger"
|
||||
"github.com/swag-gonic/gin-swagger/swaggerFiles"
|
||||
|
||||
_ "github.com/swag-gonic/gin-swagger/example/docs"
|
||||
_ "github.com/swag-gonic/gin-swagger/example/docs" // docs is generated by Swag CLI, you have to import it.
|
||||
)
|
||||
|
||||
// @title Swagger Example API
|
||||
|
|
@ -69,4 +62,6 @@ func main() {
|
|||
|
||||
r.Run()
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
5. Run it, and broswer to http://localhost:8080/swagger, you can see Swagger 2.0 Api documents.
|
||||
|
|
|
|||
Loading…
Reference in New Issue