Support nacos discovery (#108)

This commit is contained in:
澄潭
2022-12-14 14:39:06 +08:00
committed by GitHub
parent e01377f3ea
commit bf607ae554
69 changed files with 3314 additions and 319 deletions

View File

@@ -1,3 +1,17 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package address
import (

View File

@@ -1,3 +1,17 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package address
import (

View File

@@ -1,3 +1,17 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v2
import (
@@ -27,8 +41,8 @@ const (
DefaultInitTimeout = time.Second * 10
DefaultNacosTimeout = 5000
DefaultNacosLogLevel = "warn"
DefaultNacosLogDir = "log/nacos/log/"
DefaultNacosCacheDir = "log/nacos/cache/"
DefaultNacosLogDir = "/var/log/nacos/log/"
DefaultNacosCacheDir = "/var/log/nacos/cache/"
DefaultNacosNotLoadCache = true
DefaultNacosLogRotateTime = "24h"
DefaultNacosLogMaxAge = 3
@@ -75,6 +89,10 @@ func NewWatcher(cache memory.Cache, opts ...WatcherOption) (provider.Watcher, er
opt(w)
}
if w.NacosNamespace == "" {
w.NacosNamespace = w.NacosNamespaceId
}
log.Infof("new nacos2 watcher with config Name:%s", w.Name)
w.nacosClietConfig = constant.NewClientConfig(
@@ -149,7 +167,11 @@ func WithNacosSecretKey(nacosSecretKey string) WatcherOption {
func WithNacosNamespaceId(nacosNamespaceId string) WatcherOption {
return func(w *watcher) {
w.NacosNamespaceId = nacosNamespaceId
if nacosNamespaceId == "" {
w.NacosNamespaceId = "public"
} else {
w.NacosNamespaceId = nacosNamespaceId
}
}
}

View File

@@ -1,3 +1,17 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package nacos
import (
@@ -25,8 +39,8 @@ import (
const (
DefaultNacosTimeout = 5000
DefaultNacosLogLevel = "warn"
DefaultNacosLogDir = "log/nacos/log/"
DefaultNacosCacheDir = "log/nacos/cache/"
DefaultNacosLogDir = "/var/log/nacos/log/"
DefaultNacosCacheDir = "/var/log/nacos/cache/"
DefaultNacosNotLoadCache = true
DefaultNacosLogRotateTime = "24h"
DefaultNacosLogMaxAge = 3
@@ -84,6 +98,10 @@ func NewWatcher(cache memory.Cache, opts ...WatcherOption) (provider.Watcher, er
opt(w)
}
if w.NacosNamespace == "" {
w.NacosNamespace = w.NacosNamespaceId
}
log.Infof("new nacos watcher with config Name:%s", w.Name)
cc := constant.NewClientConfig(
@@ -118,7 +136,11 @@ func NewWatcher(cache memory.Cache, opts ...WatcherOption) (provider.Watcher, er
func WithNacosNamespaceId(nacosNamespaceId string) WatcherOption {
return func(w *watcher) {
w.NacosNamespaceId = nacosNamespaceId
if nacosNamespaceId == "" {
w.NacosNamespaceId = "public"
} else {
w.NacosNamespaceId = nacosNamespaceId
}
}
}