nacosx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrServiceInstanceNameEmpty = errors.New("kratos/nacos: ServiceInstance.Name can not be empty")

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.

func (*ConfigSource) Load

func (s *ConfigSource) Load() ([]*config.KeyValue, error)

Load pulls the current configuration from Nacos.

func (*ConfigSource) Watch

func (s *ConfigSource) Watch() (config.Watcher, error)

Watch listens for config changes and returns a Watcher.

type Option

type Option func(o *options)

Option is a nacos registry option.

func WithCluster

func WithCluster(cluster string) Option

WithCluster sets the cluster name.

func WithDataID

func WithDataID(dataID string) Option

WithDataID With nacos config data id.

func WithDefaultKind

func WithDefaultKind(kind string) Option

WithDefaultKind sets the default protocol kind.

func WithGroup

func WithGroup(group string) Option

WithGroup sets the group name.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets the key prefix.

func WithWeight

func WithWeight(weight float64) Option

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

func NewRegistryEngineSimple(cfg Conf) (*Registry, error)

NewRegistryEngineSimple

@Description: 手动调用简化创建流程
@param cfg
@param nc
@return *Registry
@return error

func (*Registry) Deregister

func (r *Registry) Deregister(_ context.Context, si *registry.ServiceInstance) error

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.

func (*Registry) Register

func (r *Registry) Register(_ context.Context, si *registry.ServiceInstance) error

Register registers a service instance.

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, serviceName string) (registry.Watcher, error)

Watch creates a service registryWatcher.

Jump to

Keyboard shortcuts

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