文件
    http://t.zoukankan.com/zhzhlong-p-12556457.html

    1. package main
    2. import (
    3. "github.com/gin-gonic/gin"
    4. docs "github.com/go-project-name/docs"
    5. swaggerfiles "github.com/swaggo/files"
    6. ginSwagger "github.com/swaggo/gin-swagger"
    7. "net/http"
    8. )
    9. // @BasePath /api/v1
    10. // PingExample godoc
    11. // @Summary ping example
    12. // @Schemes
    13. // @Description do ping
    14. // @Tags example
    15. // @Accept json
    16. // @Produce json
    17. // @Success 200 {string} Helloworld
    18. // @Router /example/helloworld [get]
    19. func Helloworld(g *gin.Context) {
    20. g.JSON(http.StatusOK,"helloworld")
    21. }
    22. func main() {
    23. r := gin.Default()
    24. docs.SwaggerInfo.BasePath = "/api/v1"
    25. v1 := r.Group("/api/v1")
    26. {
    27. eg := v1.Group("/example")
    28. {
    29. eg.GET("/helloworld",Helloworld)
    30. }
    31. }
    32. r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
    33. r.Run(":8080")
    34. }
    1. swag init

    image.png

    记得引入docs文件夹
    image.png