修复ghttp服务注册与回调注册重复判断问题

This commit is contained in:
John
2018-08-27 20:53:58 +08:00
parent d95628e640
commit 569adb7dd6
2 changed files with 4 additions and 3 deletions

View File

@ -70,7 +70,7 @@ type Server struct {
hooksTree map[string]interface{} // 所有注册的事件回调函数(路由表,树型结构,哈希表+链表优先级匹配)
serveCache *gcache.Cache // 服务注册路由内存缓存
hooksCache *gcache.Cache // 事件回调路由内存缓存
routesMap map[string]string // 已经注册的路由及对应的注册方法文件地址
routesMap map[string]string // 已经注册的路由及对应的注册方法文件地址(用以路由重复注册判断)
// 自定义状态码回调
hsmu sync.RWMutex // status handler互斥锁
statusHandlerMap map[string]HandlerFunc // 不同状态码下的注册处理方法(例如404状态时的处理方法)

View File

@ -61,15 +61,16 @@ func (s *Server) setHandler(pattern string, handler *handlerItem, hook ... strin
if s.Status() == SERVER_STATUS_RUNNING {
return errors.New("cannot bind handler while server running")
}
regkey := fmt.Sprintf(`%s@%v`, pattern, hook)
caller := s.getHandlerRegisterCallerLine(handler)
if line, ok := s.routesMap[pattern]; ok {
if line, ok := s.routesMap[regkey]; ok {
s := fmt.Sprintf(`duplicated route registry "%s" in %s , former in %s`, pattern, caller, line)
glog.Errorfln(s)
return errors.New(s)
} else {
defer func() {
if resultErr == nil {
s.routesMap[pattern] = caller
s.routesMap[regkey] = caller
}
}()
}