gin-swagger-gen

command module
v0.0.0-...-dc5dc8e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2021 License: MIT Imports: 3 Imported by: 0

README

gin-swagger-gen

generate gin swagger comment

install

go install github.com/hocv/gin-swagger-gen

params

param short default desc
dir d ./ project root dir
func.name f - specify the funcion to add comment
just.print p false just print, no save to file

features

add comment to gin handler function

  1. route, method
  2. params in path, query, form
  3. produce, status code
  4. accept
  5. model composition in response. e.g. jsonresult.JSONResult{data=proto.Order}

example

func route() {
    g := gin.Default()
    setRoute(g)
    _ = g.Run(":9090")
}

func setRoute(a *gin.Engine) {
    a.GET("/api/:id", normalHandle)
}

// @Summary normalHandle
// @Description normalHandle
// @Accept json,multipart/form-data
// @Produce string
// @Param id path string true "id"
// @Param lg body login true "lg"
// @Param q1 query string true "q1"
// @Param q2 query string true "q2 default 0"
// @Param f1 formData string true "f1"
// @Failure 400 {string} string
// @Success 200 {string} string
// @Router /api/{id} [get]
func normalHandle(c *gin.Context) {
    lg := &login{}
    q := c.Query("q1")
    b := c.DefaultQuery("q2", "0")
    f, _ := c.GetPostForm("f1")
    fmt.Println(q, b, f)
    if err := c.BindJSON(lg); err != nil {
        c.String(http.StatusBadRequest, "f")
        return
    }
    resp(c)
}

func resp(d *gin.Context) {
    d.String(200, "f")
}
bugs
  1. not supported BingQuery for now
  2. Other unknown

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
lib
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL