登录
首页 >  Golang >  Go问答

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

来源:stackoverflow

时间:2024-02-18 11:36:25 405浏览 收藏

从现在开始,我们要努力学习啦!今天我给大家带来《我需要帮助在我的 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学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>