Documentation
¶
Overview ¶
Package nacoscli 提供 Nacos 配置中心客户端。
Index ¶
- func GetConfig(params *Params, opts ...Option) (string, []byte, error)
- func NewClient(nacosIPAddr string, nacosPort int, nacosNamespaceID string, opts ...Option) (naming_client.INamingClient, error)
- type Client
- type Option
- func WithAuth(username, password string) Option
- func WithClientConfig(clientConfig *constant.ClientConfig) Option
- func WithContextPath(contextPath string) Option
- func WithIPAddr(ipAddr string) Option
- func WithNamespaceID(namespaceID string) Option
- func WithPort(port int) Option
- func WithScheme(scheme string) Option
- func WithServerConfigs(serverConfigs []constant.ServerConfig) Option
- func WithTimeoutMs(timeoutMs int) Option
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶ added in v1.4.40
func NewClient(nacosIPAddr string, nacosPort int, nacosNamespaceID string, opts ...Option) (naming_client.INamingClient, error)
NewClient 创建一个 Nacos 服务注册与发现客户端。
参数:
- nacosIPAddr: Nacos 服务器地址,当 opts 中指定 WithServerConfigs 时被覆盖。
- nacosPort: Nacos 服务器端口,当 opts 中指定 WithServerConfigs 时被覆盖。
- nacosNamespaceID: Nacos 命名空间 ID,当 opts 中指定 WithClientConfig 时被覆盖。
- opts: 连接配置选项,优先级高于前三项参数。
返回值:
- naming_client.INamingClient: Nacos 服务注册与发现客户端实例。
- error: 创建客户端过程中的错误。
Types ¶
type Client ¶ added in v1.4.40
type Client struct {
// contains filtered or unexported fields
}
Client 是 Nacos 配置客户端,封装了配置客户端的创建、复用与销毁。
type Option ¶
type Option func(*options)
Option 是一个函数类型,用于设置 Nacos 客户端的选项。
func WithClientConfig ¶
func WithClientConfig(clientConfig *constant.ClientConfig) Option
WithClientConfig 设置 Nacos 客户端的完整配置。 设置后将忽略 WithNamespaceID、WithTimeoutMs、WithAuth 等单字段选项。
func WithContextPath ¶ added in v1.4.40
WithContextPath 设置 Nacos 上下文路径。
func WithNamespaceID ¶ added in v1.4.40
WithNamespaceID 设置 Nacos 命名空间 ID。
func WithScheme ¶ added in v1.4.40
WithScheme 设置 Nacos 协议,支持 http 或 grpc。
func WithServerConfigs ¶
func WithServerConfigs(serverConfigs []constant.ServerConfig) Option
WithServerConfigs 设置 Nacos 服务器的完整配置列表。 设置后将忽略 WithIPAddr、WithPort、WithScheme、WithContextPath 等单字段选项。
func WithTimeoutMs ¶ added in v1.4.40
WithTimeoutMs 设置 Nacos 客户端请求超时时间(毫秒),默认 5000。
type Params ¶
type Params struct {
IPAddr string `yaml:"ipAddr" json:"ipAddr"` // 服务器地址
Port int `yaml:"port" json:"port"` // 端口
Scheme string `yaml:"scheme" json:"scheme"` // 协议,http 或 grpc
ContextPath string `yaml:"contextPath" json:"contextPath"` // 路径
NamespaceID string `yaml:"namespaceID" json:"namespaceID"` // 命名空间 ID
Group string `yaml:"group" json:"group"` // 分组,例如:dev, prod, test
DataID string `yaml:"dataID" json:"dataID"` // 配置文件 ID
Format string `yaml:"format" json:"format"` // 配置文件类型:json, yaml, toml
}
Params 包含 Nacos 配置的查询参数。
Click to show internal directories.
Click to hide internal directories.