将nacos作为go的配置中心和注册中心
Go to file
2021-04-30 11:17:50 +08:00
example nacos viper remote provider 2021-04-29 19:54:59 +08:00
example_config.yaml Update example_config.yaml 2021-04-30 11:17:50 +08:00
go.mod nacos viper remote provider 2021-04-29 19:54:59 +08:00
nacos_manager.go nacos viper remote provider 2021-04-29 19:54:59 +08:00
nacos_options.go nacos viper remote provider 2021-04-29 19:54:59 +08:00
README.md Update README.md 2021-04-29 22:13:55 +08:00
viper_manager.go nacos viper remote provider 2021-04-29 19:54:59 +08:00
viper_remote.go nacos viper remote provider 2021-04-29 19:54:59 +08:00

Viper remote for Nacos

Golang configuration,use to Viper reading from remote Nacos config systems. Viper remote for Naocs.

runtime_viper := viper.New()

remote.SetOptions(&remote.Option{
   Url:         "localhost",
   Port:        80,
   NamespaceId: "public",
   GroupName:   "DEFAULT_GROUP",
   Config: 	remote.Config{ DataId: "config_dev" },
   Auth:        nil,
})

err := remote_viper.AddRemoteProvider("nacos", "localhost", "")
remote_viper.SetConfigType("yaml")

_ = 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.

appName := remote_viper.GetString("key")   // sync get config by key

fmt.Println(appName)