Page:
ZH_Events
Pages
Actions
Basicauth
Binding
Captcha
Compress
Context
Debug
Dispatch
ErrHandler
Events
Flash
Forms
Group
Handler
Home
Injection
Logger
Params
QuickStart
Recovery
Renders
Return
Router
Session
Static
Tango
Tpongo2
Xsrf
ZH_Actions
ZH_Basicauth
ZH_Binding
ZH_Captcha
ZH_Compress
ZH_Context
ZH_Debug
ZH_Dispatch
ZH_ErrHandler
ZH_Events
ZH_Flash
ZH_Forms
ZH_Group
ZH_HOME
ZH_Handler
ZH_Injection
ZH_Logger
ZH_Params
ZH_Recovery
ZH_Renders
ZH_Return
ZH_Router
ZH_Session
ZH_Static
ZH_Tango
ZH_Tpongo2
ZH_Xsrf
6
ZH_Events
Lunny Xiao edited this page 2019-11-27 09:08:08 +08:00
Events 事件
安装
go get gitea.com/tango/events
使用
Events 中间件让你可以在方法体执行前和执行后执行相关的代码,如:
type EventAction struct {
tango.Ctx
}
func (c *EventAction) Get() {
c.Write([]byte("get"))
}
func (c *EventAction) Before() {
c.Write([]byte("before "))
}
func (c *EventAction) After() {
c.Write([]byte(" after"))
}
func main() {
t := tango.Classic()
t.Use(events.Events())
t.Get("/", new(EventAction))
t.Run()
}