README
¶
Viper remote for Nacos
Golang configuration,use to Viper reading from remote Nacos config systems. Viper remote for Naocs.
config_viper := viper.New()
remote.SetOptions(&remote.Option{
Url: "localhost",
Port: 80,
NamespaceId: "public",
GroupName: "DEFAULT_GROUP",
Config: remote.Config{ DataId: "config_dev" },
Auth: nil,
})
remote_viper := viper.New()
err := remote_viper.AddRemoteProvider("nacos", "localhost", "")
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 {
config_viper = remote_viper
fmt.Println("used remote viper")
provider := remote.NewRemoteProvider("yaml")
respChan := provider.WatchRemoteConfigOnChannel(config_viper)
go func(rc <-chan bool) {
for {
<-rc
fmt.Printf("remote async: %s", config_viper.GetString("yoyogo.application.name"))
}
}(respChan)
}
go func() {
for {
time.Sleep(time.Second * 30) // delay after each request
appName = config_viper.GetString("yoyogo.application.name")
fmt.Println("sync:" + appName)
}
}()
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultRemoteProvider ¶
func DefaultRemoteProvider() *nacosRemoteProvider
func NewNacosConfigManager ¶
func SetOptions ¶
func SetOptions(option *Option)
Types ¶
type Auth ¶
type Auth struct { Enable bool `mapstructure:"enable"` User string `mapstructure:"username"` Password string `mapstructure:"password"` // ACM Endpoint Endpoint string `mapstructure:"endpoint"` // ACM RegionId RegionId string `mapstructure:"regionId"` // ACM AccessKey AccessKey string `mapstructure:"accessKey"` // ACM SecretKey SecretKey string `mapstructure:"secretKey"` // ACM OpenKMS OpenKMS bool `mapstructure:"openKMS"` }
type ViperRemoteProvider ¶
type ViperRemoteProvider struct {
// contains filtered or unexported fields
}
func NewRemoteProvider ¶
func NewRemoteProvider(configType string) *ViperRemoteProvider
func (*ViperRemoteProvider) GetProvider ¶
func (provider *ViperRemoteProvider) GetProvider(runtimeViper *viper.Viper) *viper.Viper
func (*ViperRemoteProvider) WatchRemoteConfigOnChannel ¶
func (provider *ViperRemoteProvider) WatchRemoteConfigOnChannel(remoteViper *viper.Viper) <-chan bool
Source Files
¶
Click to show internal directories.
Click to hide internal directories.