改进ghttp回调检索方法,域名对象增加Hook方法

This commit is contained in:
John
2018-04-08 23:47:40 +08:00
parent ed61a7e86a
commit d5a35164e5
2 changed files with 12 additions and 2 deletions

View File

@ -108,6 +108,17 @@ func (d *Domain) BindControllerMethod(pattern string, c Controller, methods stri
return nil
}
// 绑定指定的hook回调函数, hook参数的值由ghttp server设定参数不区分大小写
// 目前hook支持Init/Shut
func (d *Domain)BindHookHandler(pattern string, hook string, handler HandlerFunc) error {
for domain, _ := range d.m {
if err := d.s.BindHookHandler(pattern + "@" + domain, hook, handler); err != nil {
return err
}
}
return nil
}
// 绑定URI服务注册的Init回调函数回调时按照注册顺序执行
// Init回调调用时机为请求进入控制器之前初始化Request对象之后
func (d *Domain)BindHookHandlerInit(pattern string, handler HandlerFunc) error {

View File

@ -92,8 +92,7 @@ func (s *Server)callHandler(h *HandlerItem, r *Request) {
// 按照指定hook回调函数的注册顺序进行调用
func (s *Server)callHookHandler(r *Request, hook string) {
var l []HandlerFunc
l = s.getHookList(gDEFAULT_DOMAIN, r.Method, r.URL.Path, hook)
l := s.getHookList(gDEFAULT_DOMAIN, r.Method, r.URL.Path, hook)
if l == nil {
l = s.getHookList(strings.Split(r.Host, ":")[0], r.Method, r.URL.Path, hook)
}