V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
bandian
V2EX  ›  问与答

关于 go-swagger 的使用

  •  
  •   bandian · 2020-08-14 15:38:43 +08:00 · 970 次点击
    这是一个创建于 1350 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有用 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 也没啥区别了,但之前的代码也没什么注释,想通过这种方式来重新补一下注释。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5121 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 01:19 · PVG 09:19 · LAX 18:19 · JFK 21:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.