Skip to content
Snippets Groups Projects
Commit 2b8699f3 authored by 邹毅贤's avatar 邹毅贤
Browse files

fix review comment

parent 5573269c
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ import (
gxset "github.com/dubbogo/gost/container/set"
)
var RouterUrlSet = gxset.NewSet()
var routerURLSet = gxset.NewSet()
type BaseDirectory struct {
url *common.URL
......@@ -42,6 +42,10 @@ type BaseDirectory struct {
once sync.Once
}
func GetRouterURLSet() *gxset.HashSet {
return routerURLSet
}
func NewBaseDirectory(url *common.URL) BaseDirectory {
return BaseDirectory{
url: url,
......@@ -74,9 +78,10 @@ func (dir *BaseDirectory) SetRouters(routers []cluster.Router) {
dir.routers = routers
}
func (dir *BaseDirectory) Routers() []cluster.Router {
dir.once.Do(func() {
rs := RouterUrlSet.Values()
rs := routerURLSet.Values()
for _, r := range rs {
factory := extension.GetRouterFactory(r.(*common.URL).GetParam("router", "condition"))
router, err := factory.Router(r.(*common.URL))
......
......@@ -23,7 +23,6 @@ import (
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/protocol"
)
......@@ -60,7 +59,6 @@ func (dir *staticDirectory) IsAvailable() bool {
func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invoker {
invokers := dir.invokers
localRouters := dir.routers
logger.Debug("========", len(localRouters))
if len(localRouters) == 0 {
return invokers
......
......@@ -21,6 +21,7 @@ import (
"context"
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
......
......@@ -290,10 +290,11 @@ func (c URL) Key() string {
//return c.ServiceKey()
}
//todo
func (c *URL) GetBackupUrls() []*URL {
var urls []*URL
var host string
var (
urls []*URL
host string
)
urls = append(urls, c)
backups := strings.Split(c.GetParam(constant.BACKUP_KEY, ""), "")
for _, address := range backups {
......@@ -305,7 +306,6 @@ func (c *URL) GetBackupUrls() []*URL {
} else {
host = address
}
//todo
newURL := NewURLWithOptions(
WithProtocol(c.Protocol),
WithPath(c.Path),
......
......@@ -24,6 +24,7 @@ import (
"strings"
"sync"
)
import (
"github.com/apache/dubbo-go/cluster/directory"
"github.com/apache/dubbo-go/common"
......@@ -57,8 +58,7 @@ func RouterInit(confRouterFile string) error {
}
logger.Debugf("router config{%#v}\n", routerConfig)
directory.RouterUrlSet.Add(initRouterUrl())
logger.Debug("=====", directory.RouterUrlSet.Size())
directory.GetRouterURLSet().Add(initRouterUrl())
return nil
}
......@@ -86,7 +86,10 @@ func initRouterUrl() *common.URL {
}
func parseCondition(conditions []string) string {
var when, then string
var (
when string
then string
)
for _, condition := range conditions {
condition = strings.Trim(condition, " ")
if strings.Contains(condition, "=>") {
......
......@@ -164,7 +164,7 @@ func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) {
}
func toRouters(urls []*common.URL) []cluster.Router {
if urls == nil || len(urls) == 0 {
if len(urls) == 0 {
return nil
}
......@@ -273,7 +273,6 @@ func (dir *registryDirectory) List(invocation protocol.Invocation) []protocol.In
invokers := dir.cacheInvokers
localRouters := dir.Routers()
logger.Debug("========", len(localRouters))
if len(localRouters) > 0 {
for _, router := range localRouters {
if reflect.ValueOf(router.Url()).IsValid() || router.Url().GetParamBool(constant.RUNTIME_KEY, false) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment