1、在main函數(shù)中增加全局配置,其中@name就是你確定的鑒權(quán)參數(shù)名,我的是token, @
in header 說(shuō)明參數(shù)放在header,你的鑒權(quán)代碼需要從header中獲取
// @title gin-blog API
// @version 0.0.1
// @description This is a gin blog example
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name token
// @BasePath /
2、在具體的handler里添加如下注釋?zhuān)颂幍腁piKeyAuth和main中的apike對(duì)應(yīng),切記不要修改
// @Security ApiKeyAuth
3、swagger頁(yè)面如下:

4、添加token后,后續(xù)所有有鑒權(quán)接口的header里自動(dòng)攜帶token
posted on 2019-12-23 16:08
一凡 閱讀(1993)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
Golang