Documentation
¶
Index ¶
- func GetKvConfig[T any](registryAddr string, keyName string) (*T, error)
- func GetKvConfigGlobal(keyName, group string) (string, error)
- func GetPasetoPubConfig(registryAddr string) (*hdmodel.PasetoConfig, error)
- func GetPasetoPubConfigGlobal(group string) (*hdmodel.PasetoConfig, error)
- func GetPasetoSecretConfig(registryAddr string) (*hdmodel.PasetoConfig, error)
- func GetPasetoSecretConfigGlobal(group string) (*hdmodel.PasetoConfig, error)
- func InitConfEnvs()
- func InitGlobalConfigFactory(options *ConfigFactoryOptions) error
- func InitGlobalConfigFactoryWithConsul(options *ConfigFactoryOptions) error
- func InitGlobalConfigFactoryWithNacos(options *ConfigFactoryOptions) error
- type CommonConfig
- type ConfigFactory
- func (f *ConfigFactory) Close() error
- func (f *ConfigFactory) GetCommonConfig(group string) (*CommonConfig, error)
- func (f *ConfigFactory) GetConsulClient() *ConsulConfigClient
- func (f *ConfigFactory) GetKvConfig(dataId, group string) (string, error)
- func (f *ConfigFactory) GetNacosClient() *NacosConfigClient
- func (f *ConfigFactory) GetPasetoPubConfig(group string) (*hdmodel.PasetoConfig, error)
- func (f *ConfigFactory) GetPasetoSecretConfig(group string) (*hdmodel.PasetoConfig, error)
- func (f *ConfigFactory) InitConsulClientWithParamsOrEnv(serverAddr, namespaceId, group, username, password string) error
- func (f *ConfigFactory) InitNacosClient(serverAddrs []string, namespaceId, group string, username, password string) error
- func (f *ConfigFactory) InitNacosClientFromEnv() error
- func (f *ConfigFactory) InitNacosClientWithParamsOrEnv(serverAddr, namespaceId, group, username, password string) error
- func (f *ConfigFactory) SetConfigType(configType ConfigType)
- func (f *ConfigFactory) SetOptions(options *ConfigFactoryOptions)
- type ConfigFactoryOptions
- type ConfigRequest
- type ConfigType
- type ConsulConfigClient
- func (c *ConsulConfigClient) Close() error
- func (c *ConsulConfigClient) DeleteConfig(dataId, group string) error
- func (c *ConsulConfigClient) GetCommonConfig(group string) (*CommonConfig, error)
- func (c *ConsulConfigClient) GetConfig(dataId, group string) (string, error)
- func (c *ConsulConfigClient) GetPasetoPubConfig(group string) (*hdmodel.PasetoConfig, error)
- func (c *ConsulConfigClient) GetPasetoSecretConfig(group string) (*hdmodel.PasetoConfig, error)
- func (c *ConsulConfigClient) ListenConfig(dataId, group string, callback func(content string)) error
- func (c *ConsulConfigClient) PublishConfig(dataId, group, content string) error
- func (c *ConsulConfigClient) StopAllListenConfigs() error
- func (c *ConsulConfigClient) StopListenConfig(dataId, group string) error
- func (c *ConsulConfigClient) WatchConfig(dataId, group string) (<-chan string, error)
- type NacosConfig
- type NacosConfigClient
- func (c *NacosConfigClient) BatchGetConfigs(configs []ConfigRequest) (map[string]string, error)
- func (c *NacosConfigClient) Close() error
- func (c *NacosConfigClient) DeleteConfig(dataId, group string) error
- func (c *NacosConfigClient) GetCommonConfig(group string) (*CommonConfig, error)
- func (c *NacosConfigClient) GetConfig(dataId, group string) (string, error)
- func (c *NacosConfigClient) GetConfigWithContext(ctx context.Context, dataId, group string) (string, error)
- func (c *NacosConfigClient) GetConfigWithRetry(dataId, group string, maxRetries int, retryInterval time.Duration) (string, error)
- func (c *NacosConfigClient) GetKvConfigRaw(dataId, group string) (string, error)
- func (c *NacosConfigClient) GetPasetoPubConfig(group string) (*hdmodel.PasetoConfig, error)
- func (c *NacosConfigClient) GetPasetoSecretConfig(group string) (*hdmodel.PasetoConfig, error)
- func (c *NacosConfigClient) ListenConfig(dataId, group string, callback func(string)) error
- func (c *NacosConfigClient) PublishConfig(dataId, group, content string) error
- func (c *NacosConfigClient) WatchConfigs(configs []ConfigRequest, callback func(string, string)) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetKvConfigGlobal ¶
func GetPasetoPubConfig ¶
func GetPasetoPubConfig(registryAddr string) (*hdmodel.PasetoConfig, error)
func GetPasetoPubConfigGlobal ¶
func GetPasetoPubConfigGlobal(group string) (*hdmodel.PasetoConfig, error)
func GetPasetoSecretConfig ¶
func GetPasetoSecretConfig(registryAddr string) (*hdmodel.PasetoConfig, error)
func GetPasetoSecretConfigGlobal ¶
func GetPasetoSecretConfigGlobal(group string) (*hdmodel.PasetoConfig, error)
func InitConfEnvs ¶
func InitConfEnvs()
func InitGlobalConfigFactory ¶
func InitGlobalConfigFactory(options *ConfigFactoryOptions) error
InitGlobalConfigFactory 初始化全局配置工厂
func InitGlobalConfigFactoryWithConsul ¶
func InitGlobalConfigFactoryWithConsul(options *ConfigFactoryOptions) error
InitGlobalConfigFactoryWithConsul 使用指定参数,环境变量优先
func InitGlobalConfigFactoryWithNacos ¶
func InitGlobalConfigFactoryWithNacos(options *ConfigFactoryOptions) error
InitGlobalConfigFactoryWithNacos 使用指定参数,环境变量优先
Types ¶
type CommonConfig ¶
type CommonConfig struct {
Env string
Kitex hdmodel.Kitex `yaml:"kitex"`
MySQL hdmodel.MySQL `yaml:"mysql"`
Redis hdmodel.Redis `yaml:"redis"`
OTel hdmodel.OTel `yaml:"otel"`
}
func GetCommonConfig ¶
func GetCommonConfig(registryAddr string) (*CommonConfig, error)
type ConfigFactory ¶
type ConfigFactory struct {
// contains filtered or unexported fields
}
ConfigFactory 配置工厂
func GetGlobalConfigFactory ¶
func GetGlobalConfigFactory() *ConfigFactory
GetGlobalConfigFactory 获取全局配置工厂
func NewConfigFactory ¶
func NewConfigFactory(options *ConfigFactoryOptions) *ConfigFactory
NewConfigFactory 创建配置工厂
func NewConsulConfigFactory ¶
func NewConsulConfigFactory(options *ConfigFactoryOptions) *ConfigFactory
func NewNacosConfigFactory ¶
func NewNacosConfigFactory(options *ConfigFactoryOptions) *ConfigFactory
func (*ConfigFactory) GetCommonConfig ¶
func (f *ConfigFactory) GetCommonConfig(group string) (*CommonConfig, error)
GetCommonConfig 获取通用配置(兼容接口)
func (*ConfigFactory) GetConsulClient ¶
func (f *ConfigFactory) GetConsulClient() *ConsulConfigClient
GetConsulClient 获取 Consul 客户端(用于高级操作)
func (*ConfigFactory) GetKvConfig ¶
func (f *ConfigFactory) GetKvConfig(dataId, group string) (string, error)
GetKvConfig 获取键值配置(兼容接口)
func (*ConfigFactory) GetNacosClient ¶
func (f *ConfigFactory) GetNacosClient() *NacosConfigClient
GetNacosClient 获取 Nacos 客户端(用于高级操作)
func (*ConfigFactory) GetPasetoPubConfig ¶
func (f *ConfigFactory) GetPasetoPubConfig(group string) (*hdmodel.PasetoConfig, error)
GetPasetoPubConfig 获取 Paseto 公钥配置(兼容接口)
func (*ConfigFactory) GetPasetoSecretConfig ¶
func (f *ConfigFactory) GetPasetoSecretConfig(group string) (*hdmodel.PasetoConfig, error)
GetPasetoSecretConfig 获取 Paseto 密钥配置(兼容接口)
func (*ConfigFactory) InitConsulClientWithParamsOrEnv ¶
func (f *ConfigFactory) InitConsulClientWithParamsOrEnv(serverAddr, namespaceId, group, username, password string) error
func (*ConfigFactory) InitNacosClient ¶
func (f *ConfigFactory) InitNacosClient(serverAddrs []string, namespaceId, group string, username, password string) error
InitNacosClient 初始化 Nacos 客户端
func (*ConfigFactory) InitNacosClientFromEnv ¶
func (f *ConfigFactory) InitNacosClientFromEnv() error
InitNacosClientFromEnv 从环境变量初始化 Nacos 客户端(不设置默认值,缺失则报错)
func (*ConfigFactory) InitNacosClientWithParamsOrEnv ¶
func (f *ConfigFactory) InitNacosClientWithParamsOrEnv(serverAddr, namespaceId, group, username, password string) error
InitNacosClientWithParamsOrEnv 优先使用环境变量,环境变量为空则使用传入参数;仍为空则报错
func (*ConfigFactory) SetConfigType ¶
func (f *ConfigFactory) SetConfigType(configType ConfigType)
SetConfigType 设置配置类型
func (*ConfigFactory) SetOptions ¶
func (f *ConfigFactory) SetOptions(options *ConfigFactoryOptions)
type ConfigFactoryOptions ¶
type ConfigRequest ¶
ConfigRequest 配置请求结构
type ConfigType ¶
type ConfigType string
ConfigType 配置类型
const ( ConfigTypeConsul ConfigType = "consul" ConfigTypeNacos ConfigType = "nacos" )
type ConsulConfigClient ¶
type ConsulConfigClient struct {
// contains filtered or unexported fields
}
ConsulConfigClient Consul 配置客户端
func NewConsulConfigClient ¶
func NewConsulConfigClient(serverAddr, namespaceId, group, username, password string) (*ConsulConfigClient, error)
NewConsulConfigClient 创建 Consul 配置客户端
func (*ConsulConfigClient) DeleteConfig ¶
func (c *ConsulConfigClient) DeleteConfig(dataId, group string) error
DeleteConfig 删除配置
func (*ConsulConfigClient) GetCommonConfig ¶
func (c *ConsulConfigClient) GetCommonConfig(group string) (*CommonConfig, error)
GetCommonConfig 获取通用配置
func (*ConsulConfigClient) GetConfig ¶
func (c *ConsulConfigClient) GetConfig(dataId, group string) (string, error)
GetConfig 获取配置
func (*ConsulConfigClient) GetPasetoPubConfig ¶
func (c *ConsulConfigClient) GetPasetoPubConfig(group string) (*hdmodel.PasetoConfig, error)
GetPasetoPubConfig 获取 Paseto 公钥配置
func (*ConsulConfigClient) GetPasetoSecretConfig ¶
func (c *ConsulConfigClient) GetPasetoSecretConfig(group string) (*hdmodel.PasetoConfig, error)
GetPasetoSecretConfig 获取 Paseto 密钥配置
func (*ConsulConfigClient) ListenConfig ¶
func (c *ConsulConfigClient) ListenConfig(dataId, group string, callback func(content string)) error
ListenConfig 监听配置变化(Consul 使用 blocking query)
func (*ConsulConfigClient) PublishConfig ¶
func (c *ConsulConfigClient) PublishConfig(dataId, group, content string) error
PublishConfig 发布配置
func (*ConsulConfigClient) StopAllListenConfigs ¶
func (c *ConsulConfigClient) StopAllListenConfigs() error
StopAllListenConfigs 停止所有配置监听
func (*ConsulConfigClient) StopListenConfig ¶
func (c *ConsulConfigClient) StopListenConfig(dataId, group string) error
StopListenConfig 停止监听指定配置
func (*ConsulConfigClient) WatchConfig ¶
func (c *ConsulConfigClient) WatchConfig(dataId, group string) (<-chan string, error)
WatchConfig 监听配置变化,返回配置变化通道
type NacosConfig ¶
type NacosConfig struct {
ServerConfigs []constant.ServerConfig `yaml:"server_configs"`
ClientConfig constant.ClientConfig `yaml:"client_config"`
}
NacosConfig Nacos 配置中心配置
type NacosConfigClient ¶
type NacosConfigClient struct {
// contains filtered or unexported fields
}
NacosConfigClient Nacos 配置客户端
func NewNacosConfigClient ¶
func NewNacosConfigClient(serverAddrs []string, namespaceId, group string, username, password string) (*NacosConfigClient, error)
NewNacosConfigClient 创建 Nacos 配置客户端
func NewNacosConfigClientWithConfig ¶
func NewNacosConfigClientWithConfig(config *NacosConfig) (*NacosConfigClient, error)
NewNacosConfigClientWithConfig 使用自定义配置创建 Nacos 配置客户端
func (*NacosConfigClient) BatchGetConfigs ¶
func (c *NacosConfigClient) BatchGetConfigs(configs []ConfigRequest) (map[string]string, error)
BatchGetConfigs 批量获取配置
func (*NacosConfigClient) DeleteConfig ¶
func (c *NacosConfigClient) DeleteConfig(dataId, group string) error
DeleteConfig 删除配置
func (*NacosConfigClient) GetCommonConfig ¶
func (c *NacosConfigClient) GetCommonConfig(group string) (*CommonConfig, error)
GetCommonConfig 获取通用配置
func (*NacosConfigClient) GetConfig ¶
func (c *NacosConfigClient) GetConfig(dataId, group string) (string, error)
GetConfig 获取配置
func (*NacosConfigClient) GetConfigWithContext ¶
func (c *NacosConfigClient) GetConfigWithContext(ctx context.Context, dataId, group string) (string, error)
GetConfigWithContext 带上下文的配置获取
func (*NacosConfigClient) GetConfigWithRetry ¶
func (c *NacosConfigClient) GetConfigWithRetry(dataId, group string, maxRetries int, retryInterval time.Duration) (string, error)
GetConfigWithRetry 带重试的配置获取
func (*NacosConfigClient) GetKvConfigRaw ¶
func (c *NacosConfigClient) GetKvConfigRaw(dataId, group string) (string, error)
GetKvConfigRaw 获取原始配置内容
func (*NacosConfigClient) GetPasetoPubConfig ¶
func (c *NacosConfigClient) GetPasetoPubConfig(group string) (*hdmodel.PasetoConfig, error)
GetPasetoPubConfig 获取 Paseto 公钥配置
func (*NacosConfigClient) GetPasetoSecretConfig ¶
func (c *NacosConfigClient) GetPasetoSecretConfig(group string) (*hdmodel.PasetoConfig, error)
GetPasetoSecretConfig 获取 Paseto 密钥配置
func (*NacosConfigClient) ListenConfig ¶
func (c *NacosConfigClient) ListenConfig(dataId, group string, callback func(string)) error
ListenConfig 监听配置变化
func (*NacosConfigClient) PublishConfig ¶
func (c *NacosConfigClient) PublishConfig(dataId, group, content string) error
PublishConfig 发布配置
func (*NacosConfigClient) WatchConfigs ¶
func (c *NacosConfigClient) WatchConfigs(configs []ConfigRequest, callback func(string, string)) error
WatchConfigs 批量监听配置变化