
应用的请求带有一个 http 扩展头, 例如x-my-app: 1234,类似于这样的. 想通过 beego 的 filter, 将扩展头解析出来, 然后传给 controller, 这样就不需要在每个 controller 里处理了.
controller 定义成:
type BaseController struct { my-app-value string // 这里想 hold 住扩展头里的值 beego.Controller } type MyController1 struct { BaseController } type MyController2 struct { BaseController } 但是 filter 的回调参数类型是*context.Context, 无法使用controller, 这个怎么解?
如果不是这样的方法, 还有什么更好的方法, 谢谢各位!
1 ryanking8215 OP 自问自答了, 不使用 filter, 实现 func (c *BaseController) Prepare() , 在里面取 header 参数赋值. |
2 yanyuan2046 2016-08-12 11:26:10 +08:00 远离 beego |