如何省略 swaggo 文档中的某些字段

Mar*_*ves 3 json go swagger

我正在做一个 golang API 并且需要记录它。所以我用的是 swaggo

这是一个像我的结构示例:

type calc struct {
   ID int64 `json:"id"`
   Value1 int64 `json:"value1"`
   Value2 int64 `json:"value2"`
   Result int64 `json:"result"`
}
Run Code Online (Sandbox Code Playgroud)

假设我有两条路线:

  • 获取所有计算(列表)
  • 计算一下

在执行文档时,我指定“Do a calc”路线获取像 calc 这样的 json 对象。

问题是:我使用这个结构来“读”和“写”,所以当我在“Do a calc”路线中记录时,这意味着我需要一个“json calc obejct”,但我不知道如何从规范中省略 ID 和 RESULT 字段(当然,我不需要在此路由上使用这些字段)。

小智 7

type calc struct {
   ID int64 `json:"id" swaggerignore:"true"`
   Value1 int64 `json:"value1" `
   Value2 int64 `json:"value2"`
   Result int64 `json:"result" swaggerignore:"true"`
}
Run Code Online (Sandbox Code Playgroud)

将从你的 swagger 文档中省略这些字段