nacosKit

package
v1.3.11 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package nacosKit

官方文档(英文):https://github.com/nacos-group/nacos-sdk-go 官方文档(中文):https://github.com/nacos-group/nacos-sdk-go/blob/master/README_CN.md

Package nacosKit

config(动态配置) api说明:

https://github.com/nacos-group/nacos-sdk-go/blob/master/README_CN.md#%E5%8A%A8%E6%80%81%E9%85%8D%E7%BD%AE

官方demo:

https://github.com/nacos-group/nacos-sdk-go/blob/master/example/config/main.go

Package nacosKit

Package nacosKit *

  • weight必须满足条件: >= 0 && <= 10000
  • score必须满足条件: >= 0 && <= 100

Index

Constants

This section is empty.

Variables

View Source
var (
	DebugLevel = strKit.GetStringPtr("debug")
	InfoLevel  = strKit.GetStringPtr("info")
	WarnLevel  = strKit.GetStringPtr("warn")
	ErrorLevel = strKit.GetStringPtr("error")
)

Functions

func CancelListenConfig

func CancelListenConfig(client config_client.IConfigClient, dataId, group string) error

CancelListenConfig 取消配置监听

PS: 如果未监听,将返回nil.

func DeleteConfig

func DeleteConfig(client config_client.IConfigClient, dataId, group string) (bool, error)

DeleteConfig 删除配置

@param dataId 不能为"" @param group 不能为""

PS: 如果配置不存在,将返回(true, nil).

func DeregisterInstance

func DeregisterInstance(namingClient naming_client.INamingClient, instance vo.DeregisterInstanceParam) (bool, error)

DeregisterInstance 注销实例 *

  • ClusterName 默认:DEFAULT
  • GroupName 默认:DEFAULT_GROUP

func GetConfig

func GetConfig(client config_client.IConfigClient, dataId, group string) (string, error)

GetConfig 获取配置

@param dataId 不能为"" @param group 不能为""

PS: (1) 如果不存在对应的配置,将返回("", nil); (2) 发布完立即获取配置,且之前未发布过dataId、group一致的配置,此时将得到"".(需要等一会才会发布生效,但实际场景中不存在此种情况)

func GetCriticalScore

func GetCriticalScore() float64

func ListenConfig

func ListenConfig(client config_client.IConfigClient, dataId, group string, callback func(namespaceId, dataId, group, content string)) error

ListenConfig 监听配置变化

@param dataId 不能为"" @param group 不能为""

PS: (1) 监听时,对应配置可以不存在; (2) 如果发布内容与当前内容一致,不会触发回调; (3) 能监听delete操作,如果原先配置存在,delete将触发回调,但二次delete将不会触发回调.

func NewConfigClient

func NewConfigClient(config *NacosConfig, outputDir string, logLevel NacosLogLevel) (config_client.IConfigClient, error)

NewConfigClient 动态配置客户端

使用方法详见:https://github.com/nacos-group/nacos-sdk-go/blob/master/README_CN.md#%E5%8A%A8%E6%80%81%E9%85%8D%E7%BD%AE

func NewNamingClient

func NewNamingClient(config *NacosConfig, outputDir string, logLevel NacosLogLevel) (naming_client.INamingClient, error)

NewNamingClient 服务发现客户端

使用方法详见:https://github.com/nacos-group/nacos-sdk-go/blob/master/README_CN.md#%E6%9C%8D%E5%8A%A1%E5%8F%91%E7%8E%B0

@param logDir 日志的目录(会尝试创建目录) @param level 日志级别(可以为nil,默认依据 mainControl.IsDebug())

func PublishConfig

func PublishConfig(client config_client.IConfigClient, dataId, group, content string, configType vo.ConfigType) (bool, error)

PublishConfig 发布配置

@param dataId 不能为"",且中间不能有空格 @param group 不能为"",且中间不能有空格 @param content 不能为blank @param configType 配置的类型

PS: 如果配置已存在,将覆盖.

func RegisterInstance

func RegisterInstance(namingClient naming_client.INamingClient, param vo.RegisterInstanceParam) (bool, error)

RegisterInstance 注册实例 *

  • ClusterName 默认:DEFAULT
  • GroupName 默认:DEFAULT_GROUP

func ScoreToWeight

func ScoreToWeight(score float64) (float64, error)

ScoreToWeight _

func SearchConfig

func SearchConfig(client config_client.IConfigClient, search, dataId, group string, pageNo, pageSize int) (*model.ConfigPage, error)

SearchConfig 搜索配置

TODO: 待研究,目前没遇到相关使用场景 Deprecated @param search require search=accurate--精确搜索 search=blur--模糊搜索

func SelectAllInstances

func SelectAllInstances(namingClient naming_client.INamingClient, param vo.SelectAllInstancesParam) ([]model.Instance, error)

SelectAllInstances 获取所有的实例列表

返回全部实例列表,包括:healthy=false、enable=false、weight<=0 TODO: ??? nacos1.4.2,通过此方法无法获取到“下线”的服务,难道"下线"不等于"enable == false"?后续到 nacos2.x 最新版上再试试

func SelectInstances

func SelectInstances(namingClient naming_client.INamingClient, param vo.SelectInstancesParam) ([]model.Instance, error)

SelectInstances 获取实例列表

只返回满足这些条件的实例列表:healthy=${HealthyOnly}、enable=true、weight>0. !!!:返回的错误不为nil的话,需要用进行 "nacosError" 判断.(1种特殊情况)

func SelectOneHealthyInstance

func SelectOneHealthyInstance(namingClient naming_client.INamingClient, param vo.SelectOneHealthInstanceParam) (*model.Instance, error)

SelectOneHealthyInstance 获取一个健康的实例(加权随机轮询)

按加权随机轮询的负载均衡策略返回一个健康的实例 实例必须满足的条件:health=true、enable=true、weight>0 !!!:返回的错误不为nil的话,需要用进行 "nacosError" 判断.(2种特殊情况,通过"nacosError.IsInstanceListEmpty()"和"nacosError.IsHealthyInstanceListEmpty()")

@return 2个返回值,必定有1个不为nil

func SetCriticalScore

func SetCriticalScore(score float64) error

func UpdateInstance

func UpdateInstance(namingClient naming_client.INamingClient, param vo.UpdateInstanceParam) (bool, error)

func WeightToScore

func WeightToScore(weight float64) (float64, error)

WeightToScore _

Types

type NacosConfig

type NacosConfig struct {
	ServerAddresses []string
	NamespaceId     string
	Naming          NacosNamingConfig
}

type NacosLogLevel

type NacosLogLevel *string

type NacosNamingConfig

type NacosNamingConfig struct {
	// 注册的服务实例是否是临时的?
	Ephemeral bool
}

NacosNamingConfig "服务发现"的配置

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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