Compare commits

..

4 Commits
dev ... main

Author SHA1 Message Date
e384306728 更新 'go.mod' 2022-05-25 18:46:00 +08:00
LeeX
1a0b2e62cc 2022-05-13 16:47:58 +08:00
YoyoFx
5b276dc208
Merge pull request #2 from yoyofxteam/dev
readme update
2021-07-30 11:15:35 +08:00
YoyoFx
14b8a67811
Merge pull request #1 from yoyofxteam/dev
notify event on remote config changed
2021-07-30 09:44:59 +08:00
5 changed files with 32 additions and 18 deletions

19
.gitignore vendored Normal file
View File

@ -0,0 +1,19 @@
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
.idea
vendor/
logs
go.sum

View File

@ -35,9 +35,7 @@ func (provider *ViperRemoteProvider) GetProvider(runtimeViper *viper.Viper) *vip
if err == nil {
//err = remote_viper.WatchRemoteConfigOnChannel()
if err == nil {
fmt.Println("config center ..........")
fmt.Println("used remote viper by Nacos")
fmt.Printf("Nacos config: namespace: %s , group: %s", option.NamespaceId, option.GroupName)
fmt.Println("used remote viper")
return remote_viper
}
} else {

View File

@ -2,8 +2,8 @@ package main
import (
"fmt"
remote "github.com/Echo7659/nacos-viper-remote"
"github.com/spf13/viper"
remote "github.com/yoyofxteam/nacos-viper-remote"
"os"
"os/signal"
"syscall"

6
go.mod
View File

@ -1,8 +1,8 @@
module github.com/yoyofxteam/nacos-viper-remote
module git.echol.cn/loser/nacos-viper-remote
go 1.14
require (
github.com/nacos-group/nacos-sdk-go v1.0.7
github.com/spf13/viper v1.8.1
github.com/nacos-group/nacos-sdk-go/v2 v2.0.0
github.com/spf13/viper v1.10.1
)

View File

@ -2,11 +2,11 @@ package nacos_viper_remote
import (
"fmt"
"github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/clients/config_client"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/common/logger"
"github.com/nacos-group/nacos-sdk-go/vo"
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/clients/config_client"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"github.com/spf13/viper"
"strings"
)
@ -30,8 +30,8 @@ func NewNacosConfigManager(option *Option) (*nacosConfigManager, error) {
NamespaceId: option.NamespaceId,
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
RotateTime: "1h",
MaxAge: 3,
LogDir: "logs/nacos/log",
CacheDir: "logs/nacos/cache",
LogLevel: "info",
}
@ -44,10 +44,7 @@ func NewNacosConfigManager(option *Option) (*nacosConfigManager, error) {
clientConfig.SecretKey = option.Auth.SecretKey
clientConfig.OpenKMS = option.Auth.OpenKMS
}
client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": serverConfigs,
"clientConfig": clientConfig,
})
client, err := clients.NewConfigClient(vo.NacosClientParam{ClientConfig: &clientConfig, ServerConfigs: serverConfigs})
if err != nil {
logger.Error(err.Error())
return nil, err