You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nacos-viper-remote/README.md

27 lines
813 B
Markdown

3 years ago
# Viper remote for Nacos
3 years ago
Golang configuration,use to Viper reading from remote Nacos config systems. Viper remote for Naocs.
3 years ago
```go
3 years ago
runtime_viper := viper.New()
3 years ago
3 years ago
remote.SetOptions(&remote.Option{
Url: "localhost",
Port: 80,
NamespaceId: "public",
GroupName: "DEFAULT_GROUP",
Config: remote.Config{ DataId: "config_dev" },
Auth: nil,
})
3 years ago
3 years ago
err := remote_viper.AddRemoteProvider("nacos", "localhost", "")
remote_viper.SetConfigType("yaml")
3 years ago
3 years ago
_ = remote_viper.ReadRemoteConfig() //sync get remote configs to remote_viper instance memory . for example , remote_viper.GetString(key)
_ = remote_viper.WatchRemoteConfigOnChannel() //async watch , auto refresh configs.
3 years ago
3 years ago
appName := remote_viper.GetString("key") // sync get config by key
3 years ago
3 years ago
fmt.Println(appName)
3 years ago
```