V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
bandian
V2EX  ›  问与答

关于 go-swagger 的使用

  •  
  •   bandian · Aug 14, 2020 · 1290 views
    This topic created in 2081 days ago, the information mentioned may be changed or developed.

    有用 go-swagger 的朋友吗,请教一个问题,go-swagger 支持自己手写返回响应吗

    // Package classification User API.
    //
    // The purpose of this service is to provide an application
    // that is using plain go code to define an API
    //
    //      Host: localhost:8080
    //      Version: 0.0.1
    //		Schemes: http
    // swagger:meta
    package api
    
    import (
    	"github.com/gin-gonic/gin"
    	"net/http"
    )
    
    func Pong(ctx *gin.Context) {
    	// swagger:route GET /ping checkHealth
    	//
    	// check if server is running 
    	//
    	//
    	// responses
    	//	body:
    	//		description: sever is running
    	//		schema:
    	//			type: object
    	//			required:
    	//				- code
    	//				- msg
    	//		properties:
    	//			code:
    	//				type: string
    	//			msg:
    	//				type: string
    	ctx.JSON( http.StatusOK, gin.H{
    		"code":"200",
    		"msg":"pong",
    
    	})
    }
    

    历史原因,现在项目的所有返回都是用的函数内部的变量,而不是统一的返回结构体,但是代码量太大,也没法改了,所以就想知道 go-swagger 支不支持这种自己写响应体的方式。

    虽然这种方式跟直接手撸 swagger.yml 也没啥区别了,但之前的代码也没什么注释,想通过这种方式来重新补一下注释。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4193 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 05:27 · PVG 13:27 · LAX 22:27 · JFK 01:27
    ♥ Do have faith in what you're doing.