leafee98-blog/content/essays/gin-gonic-middleware-declaration-style.md

21 lines
669 B
Markdown
Raw Normal View History

---
title: "Gin middleware 的声明格式建议"
date: 2021-02-27T10:29:11+08:00
tags: []
categories: []
weight: 50
show_comments: true
draft: false
---
一般推荐使用如下这种一个使用一个函数返回真正需要的函数的格式, 因为这样子可以自定义一些在最后的函数中的一些参数.
```
func MyMiddleware(parm interface{}) gin.HandlerFunc {
return func(*gin.Context) {
// do anything with *gin.Context and parm
}
}
```
[https://stackoverflow.com/questions/50574796/gin-gonic-middleware-declaration/50575548#50575548](https://stackoverflow.com/questions/50574796/gin-gonic-middleware-declaration/50575548#50575548)