configuration

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 17 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 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 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 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) DiscoverInstanceOne added in v0.0.2

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

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