nacos_viper_remote

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2022 License: MIT Imports: 11 Imported by: 0

README

Tks

thanks https://github.com/yoyofxteam/nacos-viper-remote

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 NewNacosConfigManager(option *Option) (*nacosConfigManager, error)

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 Config

type Config struct {
	DataId string `mapstructure:"dataId"`
}

type Option

type Option struct {
	Url         string `mapstructure:"url"`
	Port        uint64 `mapstructure:"port"`
	NamespaceId string `mapstructure:"namespace"`
	GroupName   string `mapstructure:"group"`
	Config      Config `mapstructure:"configserver"`
	Auth        *Auth  `mapstructure:"auth"`
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL