关于 go-swagger 的使用

2020-08-14 15:38:43 +08:00
 bandian

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

986 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/698281

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX