golang swagger註解說明

2021-10-06 06:46:01 字數 1541 閱讀 6935

上圖有乙個錯誤:

// @router / [post] 下面不應該有空行

// @title get product list

// @description get product list by some info

// @success 200 models.zdtproduct.productlist

// @param category_id query int false 「category id」

// @param brand_id query int false 「brand id」

// @param query query string false 「query of search」

// @param segment query string false 「segment」

// @param sort query string false 「sort option」

// @param dir query string false 「direction asc or desc」

// @param offset query int false 「offset」

// @param limit query int false 「count limit」

// @param price query float false 「price」

// @param special_price query bool false 「whether this is special price」

// @param size query string false 「size filter」

// @param color query string false 「color filter」

// @param format query bool false 「choose return format」

// @failure 400 no enough input

// @failure 500 get products common error

// @router /products [get]

func (c *cmscontroller) product() 包含,第三個是返回的物件或者字串資訊,如果是 型別,那麼 bee 工具在生成 docs 的時候會掃瞄對應的物件,這裡填寫的是想對你專案的目錄名和物件,例如 models.zdtproduct.productlist 就表示 /models/zdtproduct 目錄下的 productlist 物件。

三個引數必須通過空格分隔

failure

失敗返回的資訊,包含兩個引數,使用空格分隔,第乙個表示 status code,第二個表示錯誤資訊

@router

路由資訊,包含兩個引數,使用空格分隔,第乙個是請求的路由位址,支援正則和自定義路由,和之前的路由規則一樣,第二個引數是支援的請求方法,放在 之中,如果有多個方法,那麼使用 , 分隔。

Spring註解 Import註解

常用的匯入註解分類 註冊自己寫的類service dao controller可用包掃瞄 元件標註註解 controller service repository component bean 匯入的第三方包裡面的元件 import 快速給容器中匯入乙個元件 1 import 要匯入到容器中的元件 ...

Java 註解 元註解

retention retentionpolicy.source 註解僅存在於原始碼中,在class位元組碼檔案中不包含 retention retentionpolicy.class 預設的保留策略,註解會在class位元組碼檔案中存在,但執行時無法獲得,retention retentionpo...

spring註解之 Scope註解

1,scope註解是什麼 scope註解是springioc容器中的乙個作用域,在 spring ioc 容器中具有以下幾種作用域 基本作用域singleton 單例 prototype 多例 web 作用域 reqeust session globalsession 自定義作用域 a.single...