gin二、編碼筆記

元數據管理

gin.Context 上下文的數據在調用鏈中共享

// Keys is a key/value pair exclusively for the context of each request.
Keys map[string]interface{}

輸入數據

  • 路由參數, param
  • 請求參數, query
  • 表單參數, postform
  • 表單文件, formfile
  • 綁定, bind

輸出數據

  • header
  • cookie
  • render

中間件

  • 全局中間件 // router.Use(middleware.Logger(), gin.Recovery())
  • 局部中間件 // userRouter.GET("/profile/", middleware.Auth(), handler.UserProfile)
中間件裏面有錯誤如果不想繼續後續接口的調用不能直接return,而是應該調用c.Abort()方法。

技術資料參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章