configuration

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 19 Imported by: 0

README

configuration

Documentation

Index

Constants

View Source
const (
	KEY_IS_REMOTE     = "isRemote"
	KEY_TMP_PORT_PATH = "./tmp/port.txt"
)

Variables

This section is empty.

Functions

func Get

func Get(key string) interface{}

func GetIP

func GetIP() (string, error)

func GetIPX

func GetIPX() string

func Init

func Init(configPath string) error

func IsRemote

func IsRemote() bool

func LoadConfig

func LoadConfig(configPath string, callback func(string, string, string, string)) error

func SetILogger added in v0.0.7

func SetILogger(log ILogger)

Types

type Chooser added in v1.3.2

type Chooser struct {
	// contains filtered or unexported fields
}

Chooser 结构体用于存储实例列表及其累计权重,以便进行随机选择。

func (Chooser) Pick added in v1.3.2

func (chs Chooser) Pick() model.Instance

Pick 从Chooser中随机选择一个实例。 返回值是一个model.Instance类型,表示选择的结果。

type Config

type Config vo.NacosClientParam

type ConfigName added in v0.0.10

type ConfigName struct {
	ExtConfigFile string `yaml:"extconfigfile" json:"extconfigfile"`
	GroupName     string `yaml:"groupname" json:"groupname"`
	ServiceName   string `yaml:"servicename" json:"servicename"`
}

type DefaultLogger

type DefaultLogger struct {
}

func (*DefaultLogger) DebugCtx

func (l *DefaultLogger) DebugCtx(_ context.Context, msg string)

func (*DefaultLogger) ErrorCtx

func (l *DefaultLogger) ErrorCtx(_ context.Context, msg string)

func (*DefaultLogger) InfoCtx

func (l *DefaultLogger) InfoCtx(_ context.Context, msg string)

func (*DefaultLogger) WarnCtx

func (l *DefaultLogger) WarnCtx(_ context.Context, msg string)

type DiscoverOptionFunc added in v1.3.2

type DiscoverOptionFunc func(*discoverOptions)

定义DiscoverOptionFunc类型,它是一个函数类型,接收一个discoverOptions指针并对其进行修改

func WithChoose added in v1.3.2

func WithChoose(choose IChooseFunc) DiscoverOptionFunc

WithChoose 是一个用于设置发现选项中选择函数的 DiscoverOptionFunc 构造函数。 参数: choose - 一个实现了 IChooseFunc 接口的选择函数,用于在发现过程中进行选择逻辑的定制。 返回值: 返回一个 DiscoverOptionFunc,它是一个函数类型,接受 discoverOptions 指针作为参数,用于配置发现选项。

func WithCluster added in v1.3.2

func WithCluster(cluster string) DiscoverOptionFunc

WithCluster 返回一个DiscoverOptionFunc,用来添加一个集群名到发现选项的clusters列表中 参数cluster: 要添加的集群名

func WithGroup added in v1.3.2

func WithGroup(group string) DiscoverOptionFunc

WithGroup 返回一个DiscoverOptionFunc,用来设置发现选项中的group字段 参数group: 要设置的组名

func WithService added in v1.3.2

func WithService(service string) DiscoverOptionFunc

WithService 返回一个DiscoverOptionFunc,用来设置发现选项中的service字段 参数service: 要设置的服务名

func WithVersion added in v1.3.2

func WithVersion(version string) DiscoverOptionFunc

WithVersion 返回一个DiscoverOptionFunc,用来添加一个版本到发现选项的versions列表中 参数version: 要添加的版本号

type IChooseFunc added in v1.3.2

type IChooseFunc func(instances ...model.Instance) model.Instance

IChooseFunc 是一个函数类型,用于从多个model.Instance中选择一个。 参数instances是可变长度的model.Instance类型切片。 返回值是一个model.Instance类型,表示选择的结果。

type IConfigCenter added in v0.0.2

type IConfigCenter interface {
	AddConfigListener(id, group string, callback func(string, string, string, string)) error
	GetConfigClient() config_client.IConfigClient
	Get(key string) interface{}
	GetByID(group, id, key string) interface{}
}

type IConfigurationCenter

type IConfigurationCenter interface {
	IConfigCenter
	IRegisterCenter
	IDiscoverCenter
	SetILogger(log ILogger)
	GetServiceInfo() ServiceInfo
}
var DefaultCenter IConfigurationCenter

func NewNacos

func NewNacos(param vo.NacosClientParam, serv ServiceInfo) (IConfigurationCenter, error)

func NewSimpleNacos

func NewSimpleNacos(cfg *SimpleConfig) (IConfigurationCenter, error)

type IDiscoverCenter added in v0.0.2

type IDiscoverCenter interface {
	GetNamingClient() naming_client.INamingClient
	DiscoverInstanceOne(group, service string, clusters ...string) (string, error)
}

type ILogger

type ILogger interface {
	DebugCtx(ctx context.Context, msg string)
	InfoCtx(ctx context.Context, msg string)
	WarnCtx(ctx context.Context, msg string)
	ErrorCtx(ctx context.Context, msg string)
}

type IRegisterCenter added in v0.0.2

type IRegisterCenter interface {
	SetRealPort(port int) error
	GetIP() string
	GetPort() uint64
	GetServiceName() string
	RegisterMine(meta map[string]string) error
	RegisterServ(meta map[string]string, srvname string, port uint64) error
	DeRegisterMine() error
	DeRegisterServ(srvname string, port uint64) error
}

type InstanceSlice added in v1.3.2

type InstanceSlice []model.Instance

InstanceSlice 是model.Instance类型切片的自定义类型。

func (InstanceSlice) Len added in v1.3.2

func (a InstanceSlice) Len() int

Len 返回InstanceSlice的长度。

func (InstanceSlice) Less added in v1.3.2

func (a InstanceSlice) Less(i, j int) bool

Less 判断InstanceSlice中索引i位置的元素是否小于索引j位置的元素。 此方法用于实例的排序,基于实例的Weight属性。

func (InstanceSlice) Swap added in v1.3.2

func (a InstanceSlice) Swap(i, j int)

Swap 交换InstanceSlice中索引i和j位置的元素。

type NacosCenter

type NacosCenter struct {
	ServiceInfo
	RealPort uint64

	ConfigClient config_client.IConfigClient
	NamingClient naming_client.INamingClient
	// contains filtered or unexported fields
}

func (*NacosCenter) AddConfigListener

func (n *NacosCenter) AddConfigListener(id, group string, callback func(string, string, string, string)) error

AddConfigListener add config listen from remote nacos center

func (*NacosCenter) BatchRegisterService

func (n *NacosCenter) BatchRegisterService(param vo.BatchRegisterInstanceParam) (bool, error)

func (*NacosCenter) DeRegisterMine

func (n *NacosCenter) DeRegisterMine() error

func (*NacosCenter) DeRegisterServ added in v1.1.0

func (n *NacosCenter) DeRegisterServ(srvname string, port uint64) error

func (*NacosCenter) DeRegisterService

func (n *NacosCenter) DeRegisterService(param vo.DeregisterInstanceParam) (bool, error)

func (*NacosCenter) Discover added in v1.3.2

func (n *NacosCenter) Discover(options ...DiscoverOptionFunc) ([]model.Instance, error)

Discover 用于获取服务实例列表。 options: 可选配置项函数的集合,用于定制发现行为。 返回值: 返回符合筛选条件的服务实例列表和可能发生的错误。

func (*NacosCenter) DiscoverInstanceOne added in v0.0.2

func (n *NacosCenter) DiscoverInstanceOne(group, service string, clusters ...string) (string, error)

=========================== discover ===========================

func (*NacosCenter) DiscoverOne added in v1.3.2

func (n *NacosCenter) DiscoverOne(options ...DiscoverOptionFunc) (model.Instance, error)

DiscoverOne 用于获取单个服务实例。 options: 可选配置项函数的集合,用于定制发现行为。 返回值: 返回符合条件的单个服务实例和可能发生的错误。如果没有找到符合条件的实例,将返回一个空的实例和错误信息。

func (*NacosCenter) Get

func (n *NacosCenter) Get(key string) interface{}

Get get kv

func (*NacosCenter) GetAllService

func (n *NacosCenter) GetAllService(param vo.GetAllServiceInfoParam) (model.ServiceList, error)

func (*NacosCenter) GetByID

func (n *NacosCenter) GetByID(group, id, key string) interface{}

GetByID get kv

func (*NacosCenter) GetConfigClient added in v1.3.0

func (n *NacosCenter) GetConfigClient() config_client.IConfigClient

func (*NacosCenter) GetContent

func (n *NacosCenter) GetContent(group, id string) (string, error)

func (*NacosCenter) GetIP added in v1.2.0

func (n *NacosCenter) GetIP() string

func (*NacosCenter) GetNamingClient added in v1.3.0

func (n *NacosCenter) GetNamingClient() naming_client.INamingClient

func (*NacosCenter) GetPort

func (n *NacosCenter) GetPort() uint64

func (*NacosCenter) GetService

func (n *NacosCenter) GetService(param vo.GetServiceParam) (model.Service, error)

func (*NacosCenter) GetServiceInfo added in v1.3.0

func (n *NacosCenter) GetServiceInfo() ServiceInfo

func (*NacosCenter) GetServiceName added in v1.1.0

func (n *NacosCenter) GetServiceName() string

func (*NacosCenter) ListenContent

func (n *NacosCenter) ListenContent(group, id string, f func(namespace, group, dataId, data string)) error

func (*NacosCenter) RegisterMine

func (n *NacosCenter) RegisterMine(meta map[string]string) error

func (*NacosCenter) RegisterServ added in v1.1.0

func (n *NacosCenter) RegisterServ(meta map[string]string, srvname string, port uint64) error

func (*NacosCenter) RegisterService

func (n *NacosCenter) RegisterService(param vo.RegisterInstanceParam) (bool, error)

func (*NacosCenter) SelectAllInstances

func (n *NacosCenter) SelectAllInstances(param vo.SelectAllInstancesParam) ([]model.Instance, error)

func (*NacosCenter) SelectInstances

func (n *NacosCenter) SelectInstances(param vo.SelectInstancesParam) ([]model.Instance, error)

func (*NacosCenter) SelectOneHealthyInstance

func (n *NacosCenter) SelectOneHealthyInstance(param vo.SelectOneHealthInstanceParam) (*model.Instance, error)

func (*NacosCenter) SetConfig

func (n *NacosCenter) SetConfig(namespace, group, dataId, data string, callback func(string, string, string, string)) error

SetConfig set viper config

func (*NacosCenter) SetILogger added in v0.0.6

func (n *NacosCenter) SetILogger(log ILogger)

func (*NacosCenter) SetRealPort

func (n *NacosCenter) SetRealPort(port int) error

func (*NacosCenter) Subscribe

func (n *NacosCenter) Subscribe(param *vo.SubscribeParam)

func (*NacosCenter) UnSubscribe

func (n *NacosCenter) UnSubscribe(param *vo.SubscribeParam)

func (*NacosCenter) UpdateMine

func (n *NacosCenter) UpdateMine() error

func (*NacosCenter) UpdateServ added in v1.1.0

func (n *NacosCenter) UpdateServ(srvname string, port uint64) error

func (*NacosCenter) UpdateService

func (n *NacosCenter) UpdateService(param vo.UpdateInstanceParam) (bool, error)

type ServiceInfo

type ServiceInfo struct {
	GroupName   string       `yaml:"groupname" json:"groupname"`
	ServiceName string       `yaml:"servicename" json:"servicename"`
	ClusterName string       `yaml:"clustername" json:"clustername"`
	IP          string       `yaml:"ip" json:"ip"`
	Port        uint64       `yaml:"port" json:"port"`
	Weight      float64      `yaml:"weight" json:"weight"`
	Ephemeral   bool         `yaml:"ephemeral" json:"ephemeral"`
	Enable      bool         `yaml:"enable" json:"enable"`
	Healthy     bool         `yaml:"healthy" json:"healthy"`
	Others      []ConfigName `yaml:"others" json:"others"`
	Sentinel    ConfigName   `yaml:"sentinel" json:"sentinel"`
}

type SimpleClientConfig

type SimpleClientConfig struct {
	NamespaceId string `yaml:"namespaceid" json:"namespaceid"` // the namespaceId of Nacos.When namespace is public, fill in the blank string here.
	AppName     string `yaml:"appname" json:"appname"`         // the appName
	Endpoint    string `yaml:"endpoint" json:"endpoint"`       // the endpoint for get Nacos server addresses
	Username    string `yaml:"username" json:"username"`       // the username for nacos auth
	Password    string `yaml:"password" json:"password"`       // the password for nacos auth
}

func (*SimpleClientConfig) ToOption

func (c *SimpleClientConfig) ToOption() ([]constant.ClientOption, error)

type SimpleConfig

type SimpleConfig struct {
	Service       ServiceInfo          `yaml:"service" json:"service"`
	ClientConfig  *SimpleClientConfig  `yaml:"clientconfig" json:"clientconfig"`   // optional
	ServerConfigs []SimpleServerConfig `yaml:"serverconfigs" json:"serverconfigs"` // optional
}

func (*SimpleConfig) ToParam

func (c *SimpleConfig) ToParam() (vo.NacosClientParam, error)

type SimpleServerConfig

type SimpleServerConfig struct {
	IpAddr   string `yaml:"ipaddr" json:"ipaddr"`     // the nacos server address
	Port     uint64 `yaml:"port" json:"port"`         // nacos server port
	GrpcPort uint64 `yaml:"grpcport" json:"grpcport"` // nacos server grpc port, default=server port + 1000, this is not required
}

func (*SimpleServerConfig) ToNacosServerConfig

func (c *SimpleServerConfig) ToNacosServerConfig() constant.ServerConfig

Directories

Path Synopsis
adapter

Jump to

Keyboard shortcuts

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