Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
14b8a67811 |
27
README.md
27
README.md
@@ -3,7 +3,7 @@
|
|||||||
Golang configuration,use to Viper reading from remote Nacos config systems. Viper remote for Naocs.
|
Golang configuration,use to Viper reading from remote Nacos config systems. Viper remote for Naocs.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
config_viper := viper.New()
|
runtime_viper := viper.New()
|
||||||
|
|
||||||
remote.SetOptions(&remote.Option{
|
remote.SetOptions(&remote.Option{
|
||||||
Url: "localhost",
|
Url: "localhost",
|
||||||
@@ -14,30 +14,13 @@ remote.SetOptions(&remote.Option{
|
|||||||
Auth: nil,
|
Auth: nil,
|
||||||
})
|
})
|
||||||
|
|
||||||
remote_viper := viper.New()
|
|
||||||
err := remote_viper.AddRemoteProvider("nacos", "localhost", "")
|
err := remote_viper.AddRemoteProvider("nacos", "localhost", "")
|
||||||
remote_viper.SetConfigType("yaml")
|
remote_viper.SetConfigType("yaml")
|
||||||
err = remote_viper.ReadRemoteConfig() //sync get remote configs to remote_viper instance memory . for example , remote_viper.GetString(key)
|
|
||||||
|
|
||||||
if err == nil {
|
_ = remote_viper.ReadRemoteConfig() //sync get remote configs to remote_viper instance memory . for example , remote_viper.GetString(key)
|
||||||
config_viper = remote_viper
|
_ = remote_viper.WatchRemoteConfigOnChannel() //async watch , auto refresh configs.
|
||||||
fmt.Println("used remote viper")
|
|
||||||
provider := remote.NewRemoteProvider("yaml")
|
|
||||||
respChan := provider.WatchRemoteConfigOnChannel(config_viper)
|
|
||||||
|
|
||||||
go func(rc <-chan bool) {
|
appName := remote_viper.GetString("key") // sync get config by key
|
||||||
for {
|
|
||||||
<-rc
|
|
||||||
fmt.Printf("remote async: %s", config_viper.GetString("yoyogo.application.name"))
|
|
||||||
}
|
|
||||||
}(respChan)
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
fmt.Println(appName)
|
||||||
for {
|
|
||||||
time.Sleep(time.Second * 30) // delay after each request
|
|
||||||
appName = config_viper.GetString("yoyogo.application.name")
|
|
||||||
fmt.Println("sync:" + appName)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
```
|
```
|
||||||
|
@@ -35,9 +35,7 @@ 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("config center ..........")
|
fmt.Println("used remote viper")
|
||||||
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 {
|
||||||
|
Reference in New Issue
Block a user