将nacos作为go的配置中心和注册中心
Go to file
2021-07-30 11:15:35 +08:00
.idea provider with config type 2021-05-12 13:56:58 +08:00
example notify event on remote config changed 2021-07-29 19:30:03 +08:00
config_remote_provider.go notify event on remote config changed 2021-07-29 19:30:03 +08:00
example_config.yaml Nacos AMC or KMS 2021-06-01 19:33:47 +08:00
go.mod Upgrade dependency for viper 1.8.1 2021-06-28 11:58:11 +08:00
LICENSE Create LICENSE 2021-06-08 11:45:49 +08:00
nacos_manager.go Nacos AMC or KMS 2021-06-01 19:33:47 +08:00
nacos_options.go Nacos AMC or KMS 2021-06-01 19:33:47 +08:00
nacosprovider.go notify event on remote config changed 2021-07-29 19:30:03 +08:00
README.md notify event on remote config changed 2021-07-30 11:07:27 +08:00
viper_manager.go nacos viper remote provider 2021-04-29 19:54:59 +08:00
viper_remote.go notify event on remote config changed 2021-07-29 19:30:03 +08:00

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)
    }
}()