kvstore

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

README

registry/kvstore

This plugin provides a registry on top of a kvstore.

It's a port of registry/nats-js-kv in opencloud.

Previous Authors

Authors

License

This plugin is Apache 2.0 licensed.

Documentation

Overview

Package kvstore provides a registry plugin based on a key-value store.

Index

Constants

View Source
const Name = "kvstore"

Name provides the name of this registry.

Variables

View Source
var (
	// DefaultServiceDelimiter is the default delimiter used to separate service name and version.
	DefaultServiceDelimiter = "@"

	// DefaultDatabase is the default database name.
	DefaultDatabase = "service-registry"

	// DefaultTable is the default table name.
	DefaultTable = "service-registry"

	// DefaultTTL is the default time after which a node is considered stale.
	DefaultTTL = 10 * time.Millisecond

	// DefaultCache enables caching.
	DefaultCache = true
)

Functions

func Provide

func Provide(
	datas map[string]any,
	_ *types.Components,
	logger log.Logger,
	opts ...registry.Option,
) (registry.Type, error)

Provide creates a new memory registry.

func WithDatabase

func WithDatabase(n string) registry.Option

WithDatabase sets the database name.

func WithNoCache

func WithNoCache() registry.Option

WithNoCache disables caching.

func WithServiceDelimiter

func WithServiceDelimiter(n string) registry.Option

WithServiceDelimiter sets the service delimiter.

func WithTTL

func WithTTL(n time.Duration) registry.Option

WithTTL sets the TTL.

func WithTable

func WithTable(n string) registry.Option

WithTable sets the table name.

Types

type Config

type Config struct {
	registry.Config `yaml:",inline"`

	// ServiceDelimiter is the delimiter used to separate service name and version.
	ServiceDelimiter string `json:"serviceDelimiter" yaml:"serviceDelimiter"`

	// TTL is the time after which a node is considered stale.
	TTL config.Duration `json:"ttl" yaml:"ttl"`

	// Database is the database name in the kvstore.
	Database string `json:"database" yaml:"database"`

	// Table is the table name in the kvstore.
	Table string `json:"table" yaml:"table"`

	// Cache enables/disables caching.
	Cache bool `json:"cache" yaml:"cache"`
}

Config provides configuration for the memory registry.

func NewConfig

func NewConfig(opts ...registry.Option) Config

NewConfig creates a new config object.

func (*Config) ApplyOptions

func (c *Config) ApplyOptions(opts ...registry.Option)

ApplyOptions applies a set of options to the config.

type Registry

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

Registry is the memory registry for go-orb.

func New

func New(
	cfg Config,
	logger log.Logger,
	kvstore kvstore.Type,
) (*Registry, error)

New creates a new memory registry.

func (*Registry) Deregister

func (c *Registry) Deregister(ctx context.Context, serviceNode registry.ServiceNode) error

Deregister deregisters a service within the registry.

func (*Registry) GetService

func (c *Registry) GetService(ctx context.Context, namespace, region, name string, schemes []string) ([]registry.ServiceNode, error)

GetService returns a service from the registry.

func (*Registry) ListServices

func (c *Registry) ListServices(ctx context.Context, namespace, region string, schemes []string) ([]registry.ServiceNode, error)

ListServices lists services within the registry.

func (*Registry) Register

func (c *Registry) Register(ctx context.Context, serviceNode registry.ServiceNode) error

Register registers a service within the registry.

func (*Registry) Start

func (c *Registry) Start(ctx context.Context) error

Start starts the registry.

func (*Registry) Stop

func (c *Registry) Stop(ctx context.Context) error

Stop stops the registry.

func (*Registry) String

func (c *Registry) String() string

String returns the plugin name.

func (*Registry) Type

func (c *Registry) Type() string

Type returns the component type.

func (*Registry) Watch

Watch returns a Watcher which you can watch on.

type Watcher

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

Watcher is used to keep track of changes in the registry.

func NewWatcher

func NewWatcher(s *Registry) (*Watcher, error)

NewWatcher returns a new watcher.

func (*Watcher) Next

func (w *Watcher) Next() (*registry.Result, error)

Next returns the next result. It is a blocking call.

func (*Watcher) Stop

func (w *Watcher) Stop() error

Stop stops the watcher.

Jump to

Keyboard shortcuts

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