应用的请求带有一个 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
, 这个怎么解?
如果不是这样的方法, 还有什么更好的方法, 谢谢各位!
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.