Swagger documentation is generated from the code using go-swagger package.
- step: Get dependency witch contains a golang implementation of Swagger 2.0
go get -u github.com/go-swagger/go-swagger/cmd/swagger
-
step: Adding metadata in your code.
-
step: Generate the file swagger.yaml using the following command:
swagger generate spec -o ./swagger.yaml --scan-models
- step: If you want swagger-ui import the package go-openapi in your code
import "github.com/go-openapi/runtime/middleware"
- step: running your code:
go run main.go
Swagger documentation can be viewed in your browser at:
swagger-ui: http://localhost:8080/docs.
swagger-spec: http://localhost:8080/swagger.yaml
see guide