From 1a0b2e62ccf26886c3167e16d9192f679a813f9c Mon Sep 17 00:00:00 2001 From: LeeX Date: Fri, 13 May 2022 16:47:58 +0800 Subject: [PATCH] :sparkles: --- .gitignore | 19 +++++++++++++++++++ example/main.go | 2 +- go.mod | 6 +++--- nacos_manager.go | 19 ++++++++----------- 4 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e6550ee --- /dev/null +++ b/.gitignore @@ -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 diff --git a/example/main.go b/example/main.go index 8ab844f..8949b86 100644 --- a/example/main.go +++ b/example/main.go @@ -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" diff --git a/go.mod b/go.mod index b4f2c04..27a7218 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ -module github.com/yoyofxteam/nacos-viper-remote +module github.com/Echo7659/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 ) diff --git a/nacos_manager.go b/nacos_manager.go index 2df06b9..8de4ee1 100644 --- a/nacos_manager.go +++ b/nacos_manager.go @@ -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