manual-zh-CN/chapter-12
Lunny Xiao aa1c88f1b7
Change to new gitea address
2019-11-17 16:17:05 +08:00
..
README.md Change to new gitea address 2019-11-17 16:17:05 +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()
}