我需要帮助在我的 Go 程序中生成 Swagger UI

作者:佚名

时间:2024-02-18

来源:stackoverflow

浏览:405

我是golang和api的新手。我们有服务文件,其中包含getbookhistory(contextcontext,bookstring)([]*model.lookuprecord,error){//somecode}在我的rest.go(处理程序)中//getbookhistorylookupgodoc//@summaryshowshistoricdetailedinfo.//@descriptiongethistorydetailsfro

从现在开始,我们要努力学习啦!今天我给大家带来《我需要帮助在我的 Go 程序中生成 Swagger UI》,感兴趣的朋友请继续看下去吧!下文中的内容我们主要会涉及到等等知识点,如果在阅读本文过程中有遇到不清楚的地方,欢迎留言呀!我们一起讨论,一起学习!

问题内容

我是 golang 和 api 的新手。

我们有服务文件,其中包含

getbookhistory(context context, book string)([]*model.lookuprecord, error){
//some code
}

在我的rest.go(处理程序)中

// getbookhistorylookup godoc
// @summary shows historic detailed  info.
// @description get history details from the  table in the database.
// @param book path string true "book"
// @produce  json
// @success 200 {object} imodel.lookuprecord
// @router /history/{book} [get] 
func(h handler) getbookhistorylookup(c echo.context){
//some code
}

我正在使用 github.com/swaggo/swag/cmd/swag lib。

它生成一个 swaggerui,但此获取服务的响应为空。 我可以看到返回类型是数组,需要更改为该行

// @Success 200 {object} iModel.LookupRecord

谢谢


正确答案


// @success 200 {object} imodel.lookuprecord

替换为

// @Success 200 {object} []iModel.LookupRecord

本篇关于《我需要帮助在我的 Go 程序中生成 Swagger UI》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

本文内容来源于互联网,如有侵权请联系删除。

相关文章

更多

热门专题

更多
返回顶部