Alanxtl commented on code in PR #777:
URL: https://github.com/apache/dubbo-go-pixiu/pull/777#discussion_r2553748205
##########
pkg/common/router/router.go:
##########
@@ -133,40 +189,44 @@ func (rm *RouterCoordinator) initRegex() {
// OnAddRouter add router
func (rm *RouterCoordinator) OnAddRouter(r *model.Router) {
- //TODO: lock move to trie 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, constant.Options}
- }
- 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.mu.Lock()
+ defer rm.mu.Unlock()
+ rm.nextSnapshot[r.ID] = r
+ rm.schedulePublishLocked()
+}
+
+func fillTrieFromRoutes(cfg *model.RouteConfiguration) {
+ for _, r := range cfg.Routes {
+ methods := r.Match.Methods
+ if len(methods) == 0 {
+ methods = []string{"GET", "POST", "PUT", "DELETE",
"PATCH", "OPTIONS", "HEAD"}
+ }
+ for _, m := range methods {
+ key := stringutil.GetTrieKeyWithPrefix(m, r.Match.Path,
r.Match.Prefix, r.Match.Prefix != "")
+ _, _ = cfg.RouteTrie.Put(key, r.Route)
}
- _, _ = rm.activeConfig.RouteTrie.Put(key, r.Route)
}
}
// OnDeleteRouter delete router
func (rm *RouterCoordinator) OnDeleteRouter(r *model.Router) {
- 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.mu.Lock()
+ defer rm.mu.Unlock()
+ delete(rm.nextSnapshot, r.ID)
+ rm.schedulePublishLocked()
+}
+
+func matchHeaders(chs []model.CompiledHeader, r *stdHttp.Request) bool {
Review Comment:
任意一个匹配上就算匹配上了
--
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]