mark4z commented on a change in pull request #262:
URL: https://github.com/apache/dubbo-go-pixiu/pull/262#discussion_r720780340
##########
File path: pkg/common/router/router.go
##########
@@ -54,23 +55,50 @@ func (rm *RouterCoordinator) Route(hc *http.HttpContext)
(*model.RouteAction, er
return rm.activeConfig.Route(hc.Request)
}
+func getTrieKey(method string, path string, isPrefix bool) string {
+ if isPrefix {
+ return method + constant.PathSlash + path + constant.PathSlash
+ "**"
+ }
+ return method + constant.PathSlash + path
+}
+
// OnAddRouter add router
func (rm *RouterCoordinator) OnAddRouter(r *model.Router) {
+ //锁粒度 下期优化到 字典树node 级别
rm.rw.Lock()
defer rm.rw.Unlock()
+ if r.Match.Methods == nil {
+ r.Match.Methods = []string{constant.Get, constant.Put,
constant.Delete, constant.Post}
+ }
+ isPrefix := r.Match.Prefix != ""
+ for _, method := range r.Match.Methods {
+ var key string
+ if isPrefix {
+ key = getTrieKey(method, r.Match.Prefix, isPrefix)
+ } else {
+ key = getTrieKey(method, r.Match.Path, isPrefix)
+ }
+ rm.activeConfig.RouteTrie.Put(key, r.Route)
+ }
Review comment:
resolve it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]