开发框架要好用,可扩展性、赋予开发者的介入能力很重要。为此我们设计了一套事件机制,让开发人员能够自由介入每次请求的全生命周期,通过Context携带的资源在事件处理函数间自由翱翔。

生命周期

目前事件设计的还很不合理,跟其它模块关联比较多。思路是这样,以后慢慢调整。

Incoming Request
  │
  └─▶ Routing
        │
        └─▶ Instance Logger
             │
   4**/5** ◀─┴─▶ Before Event
                  │
        4**/5** ◀─┴─▶ User Handler
                        │
              4**/5** ◀─┴─▶ PreSend Event
                             │
                   4**/5** ◀─┴─▶ Sending...
                                  │
                            415 ◀─┴─▶ AfterSend Event
                                        │
                              4**/5** ◀─┴─▶ After Event
                                              │
                                              └─▶ END

应用级事件

应用启动之后,在开始监听端口之后调用OnReady事件,应用关闭退出之前调用OnClose事件

1
2
3
4
5
6
7
8
9
app.OnReady(func(fast *fst.GoFast) {
	log.Println("App OnReady Call.")
	log.Printf("Listening and serving HTTP on %s\n", "127.0.0.1:8099")
})

app.OnClose(func(fast *fst.GoFast) {
	log.Println("App OnClose Call.")
})

路由事件

分组或路由项事件是一样的,现在支持下面四个,以后慢慢扩展和调整

1
2
3
4
tst.Before(handler("before tst_url"))
tst.After(handler("after tst_url"))
tst.PreSend(handler("preSend tst_url"))
tst.AfterSend(handler("afterSend tst_url"))

(未完待续…)