Documentation
¶
Index ¶
- Variables
- func NewConfigClient(cfg Conf) (iClient config_client.IConfigClient, err error)
- func NewConfigSource(cli config_client.IConfigClient, opts ...Option) config.Source
- func NewNacosConfigSource(cfg Conf, cc config_client.IConfigClient) (config.Source, error)
- func NewNamingClient(cfg Conf) (naming_client.INamingClient, error)
- type Conf
- type ConfigSource
- type Option
- type Registry
- func (r *Registry) Deregister(_ context.Context, si *registry.ServiceInstance) error
- func (r *Registry) GetService(_ context.Context, serviceName string) ([]*registry.ServiceInstance, error)
- func (r *Registry) Register(_ context.Context, si *registry.ServiceInstance) error
- func (r *Registry) Watch(ctx context.Context, serviceName string) (registry.Watcher, error)
Constants ¶
This section is empty.
Variables ¶
var ErrServiceInstanceNameEmpty = errors.New("kratos/nacos: ServiceInstance.Name can not be empty")
var ProviderSet = wire.NewSet( NewNamingClient, NewConfigClient, NewRegistryEngine, )
Functions ¶
func NewConfigClient ¶
func NewConfigClient(cfg Conf) (iClient config_client.IConfigClient, err error)
NewConfigClient
@Description: 如果 cfg.Addr == "" || cfg.Port == 0 则返回 nil, 需要外部兼容 @param cfg @return iClient @return err
func NewConfigSource ¶
func NewConfigSource(cli config_client.IConfigClient, opts ...Option) config.Source
NewConfigSource creates a Nacos config source with the given client and shared options. Default DataID is "application.yaml" and Group is constant.DEFAULT_GROUP. Use shared Option functions (WithDataID, WithGroup, WithCluster, WithPrefix, etc.) to customize.
func NewNacosConfigSource ¶
func NewNacosConfigSource(cfg Conf, cc config_client.IConfigClient) (config.Source, error)
func NewNamingClient ¶
func NewNamingClient(cfg Conf) (naming_client.INamingClient, error)
NewNamingClient
@Description: 如果 cfg.Addr == "" || cfg.Port == 0 则返回 nil, 需要外部兼容 @param cfg @return naming_client.INamingClient @return error
Types ¶
type Conf ¶
type Conf struct {
Addr string // Nacos server address
Port uint64 // Nacos server port
Username string // optional auth
Password string // optional auth
ClusterName string // Prefix and cluster name for Nacos registrations
NamespaceId string // for both config and naming
GroupId string // naming group / config group
DataId string // config data ID
LogDir string // config data ID
Weight int32 // config data ID
Scheme string // http / https (optional; auto set to https when TLS enabled)
// TLS / mTLS
EnableTLS bool // enable TLS (set true for https)
TLSTrustAll bool // if true, skip verifying server cert (NOT recommended for production)
TLSCAFile string // PEM CA bundle path for verifying server cert
TLSCertFile string // PEM client certificate path (mTLS)
TLSKeyFile string // PEM client private key path (mTLS)
}
Conf holds the Nacos configuration. Addr, Port, Username, Password specify the server connection. ClusterName serves as both the key prefix and cluster name for service discovery/registration. NamespaceId isolates environments or tenants; GroupId logically groups configs and services. DataId identifies specific config items in Nacos.
type ConfigSource ¶
type ConfigSource struct {
// contains filtered or unexported fields
}
ConfigSource implements kratos config.Source using a provided Nacos SDK v2 client.
type Option ¶
type Option func(o *options)
Option is a nacos registry option.
func WithDefaultKind ¶
WithDefaultKind sets the default protocol kind.
func WithWeight ¶
WithWeight sets the default instance weight.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a Nacos registry.
func New ¶
func New(cli naming_client.INamingClient, opts ...Option) *Registry
New creates a new Nacos registry.
func NewRegistryEngine ¶
func NewRegistryEngine(cfg Conf, nc naming_client.INamingClient) (*Registry, error)
NewRegistryEngine
@Description: 如果 cfg.Addr == "" || cfg.Port == 0 则返回 nil, 需要外部兼容 @param cfg @param nc @return *Registry @return error
func NewRegistryEngineSimple ¶
NewRegistryEngineSimple
@Description: 手动调用简化创建流程 @param cfg @param nc @return *Registry @return error
func (*Registry) Deregister ¶
Deregister deregisters a service instance.
func (*Registry) GetService ¶
func (r *Registry) GetService(_ context.Context, serviceName string) ([]*registry.ServiceInstance, error)
GetService retrieves instances of a service.