This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git
The following commit(s) were added to refs/heads/develop by this push:
new 6979562c style:optimization router match prefix definition
new 8d189f84 Merge pull request #451 from
baerwang/style-router-match-prefix
6979562c is described below
commit 6979562ce842cd3de8bdc4208633a003e08a52eb
Author: wangxiaoxiong <[email protected]>
AuthorDate: Tue Jun 28 10:00:45 2022 +0800
style:optimization router match prefix definition
---
pkg/adapter/springcloud/cloud.go | 3 +--
pkg/adapter/springcloud/servicediscovery/servicediscovery.go | 3 +--
pkg/model/router.go | 4 ++++
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/pkg/adapter/springcloud/cloud.go b/pkg/adapter/springcloud/cloud.go
index b5fb0298..467a9cdd 100644
--- a/pkg/adapter/springcloud/cloud.go
+++ b/pkg/adapter/springcloud/cloud.go
@@ -327,8 +327,7 @@ func (a *CloudAdapter) fetchCompareAndSet() {
// third add new router
for _, c := range newStore.Config {
if !oldStore.HasCluster(c.Name) {
- prefix := "/" + c.Name + "/"
- match := model.RouterMatch{Prefix: prefix}
+ match := model.NewRouterMatchPrefix(c.Name)
route := model.RouteAction{Cluster: c.Name}
added := &model.Router{ID: c.Name, Match: match, Route:
route}
rm.AddRouter(added)
diff --git a/pkg/adapter/springcloud/servicediscovery/servicediscovery.go
b/pkg/adapter/springcloud/servicediscovery/servicediscovery.go
index 60ffcb1a..d85bc7f8 100644
--- a/pkg/adapter/springcloud/servicediscovery/servicediscovery.go
+++ b/pkg/adapter/springcloud/servicediscovery/servicediscovery.go
@@ -81,8 +81,7 @@ func (i *ServiceInstance) ToEndpoint() *model.Endpoint {
// ToRoute route ID is cluster name, so equal with endpoint name and
routerMatch prefix is also service name
func (i *ServiceInstance) ToRoute() *model.Router {
- prefix := "/" + i.ServiceName + "/"
- rm := model.RouterMatch{Prefix: prefix}
+ rm := model.NewRouterMatchPrefix(i.ServiceName)
ra := model.RouteAction{Cluster: i.ServiceName}
return &model.Router{ID: i.ServiceName, Match: rm, Route: ra}
}
diff --git a/pkg/model/router.go b/pkg/model/router.go
index af8fc6f1..370ec41c 100644
--- a/pkg/model/router.go
+++ b/pkg/model/router.go
@@ -71,6 +71,10 @@ type (
}
)
+func NewRouterMatchPrefix(name string) RouterMatch {
+ return RouterMatch{Prefix: "/" + name + "/"}
+}
+
func (rc *RouteConfiguration) RouteByPathAndMethod(path, method string)
(*RouteAction, error) {
if rc.RouteTrie.IsEmpty() {
return nil, errors.Errorf("router configuration is empty")