nacoscli

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 10 Imported by: 0

README

nacoscli

从nacos配置中心获取配置并解析到结构体。

使用示例

	// 方式一:设置参数
	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 := Init(a, params)

	// 方式二:设置ClientConfig和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 = Init(a, params,
		WithClientConfig(clientConfig),
		WithServerConfigs(serverConfigs),
	)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(obj interface{}, params *Params, opts ...Option) error

Init 从nacos获取配置并解析到struct

func NewNamingClient

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

NewNamingClient 实例化服务注册和发现nacos客户端

Types

type Option

type Option func(*options)

Option set the nacos client options.

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 // nacos 服务地址
	Port        uint64 // nacos 服务端口
	Scheme      string // http或https
	ContextPath string // path
	NamespaceID string // 名称空间id

	Group  string // 分组,dev, prod, test
	DataID string // 配置文件id
	Format string // 配置文件类型: json,yaml,toml
	// contains filtered or unexported fields
}

Params nacos参数

Jump to

Keyboard shortcuts

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