nacoscli

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 8 Imported by: 0

README

nacoscli

Get the configuration from the nacos configuration center.

Example of use

	import "gitee.com/yzsunjianguo/sponge/pkg/nacoscli"

	// Way 1: setting parameters
	a := &config{}
	params := &Params{
		IpAddr:      "192.168.3.37",
		Port:        8848,
		NamespaceId: "de7b176e-91cd-49a3-ac83-beb725979775",
		Group:       "dev",
		DataId:      "user-srv.yml",
		Format:      "yaml",
	}
	_, _, err = GetConfig(params)

	// Way 2: setting up ClientConfig and ServerConfig
	a = &config{}
	params = &Params{
		Group:  "dev",
		DataId: "user-srv.yml",
		Format: "yaml",
	}
	clientConfig := &constant.ClientConfig{
		NamespaceId:         "de7b176e-91cd-49a3-ac83-beb725979775",
		TimeoutMs:           5000,
		NotLoadCacheAtStart: true,
		LogDir:              os.TempDir() + "/nacos/log",
		CacheDir:            os.TempDir() + "/nacos/cache",
	}
	serverConfigs := []constant.ServerConfig{
		{
			IpAddr: "192.168.3.37",
			Port:   8848,
		},
	}
	_, _, err = GetConfig(params,
		WithClientConfig(clientConfig),
		WithServerConfigs(serverConfigs),
	)

Documentation

Overview

Package nacoscli provides for getting the configuration from the nacos configuration center and parse it into a structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfig

func GetConfig(params *Params, opts ...Option) (string, []byte, error)

GetConfig get configuration from nacos

func Init deprecated

func Init(_ interface{}, _ *Params, _ ...Option) error

Init get configuration from nacos and parse to struct, use for configuration center

Deprecated: use GetConfig instead.

func NewNamingClient

func NewNamingClient(nacosIPAddr string, nacosPort int, nacosNamespaceID string, opts ...Option) (naming_client.INamingClient, error)

NewNamingClient create a service registration and discovery of nacos client. Note: If parameter WithClientConfig is set, nacosNamespaceID is invalid, if parameter WithServerConfigs is set, nacosIPAddr and nacosPort are invalid.

Types

type Option

type Option func(*options)

Option set the nacos client options.

func WithAuth

func WithAuth(username string, password string) Option

WithAuth set authentication

func WithClientConfig

func WithClientConfig(clientConfig *constant.ClientConfig) Option

WithClientConfig set nacos client config

func WithServerConfigs

func WithServerConfigs(serverConfigs []constant.ServerConfig) Option

WithServerConfigs set nacos server config

type Params

type Params struct {
	IPAddr      string // server address
	Port        uint64 // port
	Scheme      string // http or grpc
	ContextPath string // path

	NamespaceID string // namespace id

	Group  string // group, example: dev, prod, test
	DataID string // config file id
	Format string // configuration file type: json,yaml,toml
	// contains filtered or unexported fields
}

Params nacos parameters

Jump to

Keyboard shortcuts

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