Compare commits

..

1 Commits
main ... dev

Author SHA1 Message Date
yoyofx
a16a88e3c9 print namespace and gourpname by nacos 2021-07-30 12:26:44 +08:00
5 changed files with 18 additions and 32 deletions

19
.gitignore vendored
View File

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

View File

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

6
go.mod
View File

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

View File

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