Auto generate API Documentation Go using framework Gin
This package makes it easy for developers to create documentation automatically using the gin framework in the Golang programming language.
Install the package with:
go get github.com/didintri196/gin-docs
Import it with:
import builder "github.com/didintri196/gin-docs"
and use builder
as the package name inside the code.
Please check the example folder for details.
package main
import (
builder "github.com/didintri196/gin-docs"
)
func Middleware() {
router := gin.Default()
router.Use(gin.Recovery())
router.Use(cors.Middleware(cors.Config{
Origins: "*",
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type,Access-Control-Allow-Origin",
ExposedHeaders: "",
Credentials: true,
ValidateHeaders: false,
}))
api := router.Group("/api")
{
Machine := new(controllers.Machine)
api.GET("/list", Machine.GetDeviceCmdAll)
api.GET("/ceksn", Machine.GetDeviceCmd)
api.POST("/postdata/:sn", Machine.PostData)
}
router.GET("", func(c *gin.Context) {
c.JSON(200, gin.H{"messsage": "API ON"})
})
builder.Use(router) <--- using here
router.Run(":9001")
}
Using function Use(*gin.Engine)
builder.Use(router)
How to run to generate documentation
$ ./project -doc=markdown