Feat registry consul (#445)

Co-authored-by: johnlanni <zty98751@alibaba-inc.com>
This commit is contained in:
Jun
2023-08-01 16:16:28 +08:00
committed by GitHub
parent e5105a4d71
commit 9b88c6bb40
16 changed files with 1049 additions and 84 deletions

View File

@@ -67,6 +67,7 @@ type watcher struct {
addrProvider *address.NacosAddressProvider
updateCacheWhenEmpty bool
nacosClietConfig *constant.ClientConfig
authOption provider.AuthOption
}
type WatcherOption func(w *watcher)
@@ -106,6 +107,8 @@ func NewWatcher(cache memory.Cache, opts ...WatcherOption) (provider.Watcher, er
constant.WithNamespaceId(w.NacosNamespaceId),
constant.WithAccessKey(w.NacosAccessKey),
constant.WithSecretKey(w.NacosSecretKey),
constant.WithUsername(w.authOption.NacosUsername),
constant.WithPassword(w.authOption.NacosPassword),
)
initTimer := time.NewTimer(DefaultInitTimeout)
@@ -224,6 +227,12 @@ func WithUpdateCacheWhenEmpty(enable bool) WatcherOption {
}
}
func WithAuthOption(authOption provider.AuthOption) WatcherOption {
return func(w *watcher) {
w.authOption = authOption
}
}
func (w *watcher) Run() {
ticker := time.NewTicker(time.Duration(w.NacosRefreshInterval))
defer ticker.Stop()

View File

@@ -64,6 +64,7 @@ type watcher struct {
client *versionedclient.Clientset
isStop bool
updateCacheWhenEmpty bool
authOption provider.AuthOption
}
type WatcherOption func(w *watcher)
@@ -193,6 +194,12 @@ func WithUpdateCacheWhenEmpty(enable bool) WatcherOption {
}
}
func WithAuthOption(authOption provider.AuthOption) WatcherOption {
return func(w *watcher) {
w.authOption = authOption
}
}
func (w *watcher) Run() {
ticker := time.NewTicker(time.Duration(w.NacosRefreshInterval))
defer ticker.Stop()