discovery

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEntryTypeNotMatch = errors.New("discovery entry node type not match")
	ErrEntryUnmarshalKey = errors.New("discovery entry unmashal key failed")
)

Functions

func InstallDiscoveryOptionsWatchDog

func InstallDiscoveryOptionsWatchDog(dog func(cc *DiscoveryOptions))

InstallDiscoveryOptionsWatchDog install watch dog

func InstallRegistryOptionsWatchDog

func InstallRegistryOptionsWatchDog(dog func(cc *RegistryOptions))

InstallRegistryOptionsWatchDog install watch dog

Types

type Client

type Client = network.Client

type Discovery

type Discovery interface {
	Watch(ctx context.Context) (changes <-chan Entries, err error)
	GetAll(ctx context.Context) (all Entries, err error)
	Close(ctx context.Context)
	WatchEventNotify(ctx context.Context, eventNotify func(Entries)) (err error)
}

Discovery use for discover netwrok service entry

func NewDiscovery

func NewDiscovery(path string, opts ...DiscoveryOption) (_ Discovery, err error)

type DiscoveryOption

type DiscoveryOption func(cc *DiscoveryOptions) DiscoveryOption

DiscoveryOption option define

func WithDiscoveryOptionCodec

func WithDiscoveryOptionCodec(v EntryCodec) DiscoveryOption

Codec use for decode entry.

func WithDiscoveryOptionFrameLogger

func WithDiscoveryOptionFrameLogger(v *zaplog.Logger) DiscoveryOption

frame log

func WithDiscoveryOptionNewEntry

func WithDiscoveryOptionNewEntry(v func() Entry) DiscoveryOption

NewEntry create custom entry for discovery new entry

func WithDiscoveryOptionStore

func WithDiscoveryOptionStore(v kvstore.Store) DiscoveryOption

Store use for discover entries

type DiscoveryOptions

type DiscoveryOptions struct {
	// NewEntry create custom entry for discovery new entry
	NewEntry func() Entry
	// Codec use for decode entry.
	Codec EntryCodec
	// Store use for discover entries
	Store kvstore.Store
	// frame log
	FrameLogger *zaplog.Logger
}

func NewDiscoveryOptions

func NewDiscoveryOptions(opts ...DiscoveryOption) *DiscoveryOptions

NewDiscoveryOptions create options instance.

func (*DiscoveryOptions) ApplyOption

func (cc *DiscoveryOptions) ApplyOption(opts ...DiscoveryOption)

ApplyOption modify options

func (*DiscoveryOptions) GetSetOption

func (cc *DiscoveryOptions) GetSetOption(opt DiscoveryOption) DiscoveryOption

GetSetOption modify and get last option

func (*DiscoveryOptions) SetOption

func (cc *DiscoveryOptions) SetOption(opt DiscoveryOption)

SetOption modify options

type Entries

type Entries []Entry

Entries is a list of *Entry with some helpers.

func (Entries) Contains

func (e Entries) Contains(entry Entry) bool

Contains returns true if the Entries contain a given Entry.

func (Entries) Diff

func (e Entries) Diff(cmp Entries) (Entries, Entries)

Diff compares two entries and returns the added and removed entries.

func (Entries) Equals

func (e Entries) Equals(cmp Entries) bool

Equals returns true if cmp contains the same data.

type Entry

type Entry interface {
	// Equals returns true if cmp contains the same data.
	Equals(Entry) bool
	// String returns the string form of an entry.
	String() string
	// Metadata get entry metadate
	Metadata(key string) string
	// Address
	Address() (network, addr string)
	// BalanceName get balance name
	BalanceName() string
	// State return node state
	State() EntryState
	// ModifyState use for modify entry state
	ModifyState(state EntryState)
	// Client
	Client() network.Client
	SetClient(network.Client)
}

An Entry represents a node.

type EntryCodec

type EntryCodec interface {
	// Marshal marshal key/value to store.
	Mashal(e Entry) (key string, value []byte, err error)
	// Unmarshal unmarshal key/value from store.
	Unmarshal(e Entry, key string, value []byte) (err error)
}

EntryCodec Use for encode/decode entry from store EntryCodec 用于序列化和反序列化从store读取的信息

var NodeJsonEntryCodec EntryCodec = jsonEntryCodec{}

type EntryState

type EntryState int8

EntryState entry state

const (
	EntryStateOffline EntryState = iota
	EntryStateOnline
)

type NoOpDiscovery

type NoOpDiscovery struct{}

func (NoOpDiscovery) Close

func (NoOpDiscovery) Close(ctx context.Context)

func (NoOpDiscovery) GetAll

func (NoOpDiscovery) GetAll(ctx context.Context) (all Entries, err error)

func (NoOpDiscovery) Watch

func (NoOpDiscovery) Watch(ctx context.Context) (changes <-chan Entries, err error)

func (NoOpDiscovery) WatchEventNotify

func (NoOpDiscovery) WatchEventNotify(ctx context.Context, eventNotify func(Entries)) (err error)

type NoOpRegistry

type NoOpRegistry struct{}

func (NoOpRegistry) Clean

func (NoOpRegistry) Clean(ctx context.Context) (err error)

Close clean entry info

func (NoOpRegistry) GetEntry added in v0.0.2

func (NoOpRegistry) GetEntry() Entry

GetEntry get current node's Entry

func (NoOpRegistry) NewEntry

func (NoOpRegistry) NewEntry(ctx context.Context, addr net.Addr) (err error)

NewEntry create entry,wait for register

func (NoOpRegistry) Offline

func (NoOpRegistry) Offline(ctx context.Context) (err error)

Offline set entry offline status and update to store

func (NoOpRegistry) Online

func (NoOpRegistry) Online(ctx context.Context) (err error)

Online set entry online status and update to store

func (NoOpRegistry) UpdateEntry added in v0.0.2

func (NoOpRegistry) UpdateEntry(ctx context.Context) (err error)

UpdateEntry

type Node

type Node struct {
	// Identifier use for register path
	Identifier string            `json:"-"`
	Network    string            `json:"net,omitemtpy"`
	Addr       string            `json:"addr"`
	Balance    string            `json:"bn,omitemtpy"`
	Status     int               `json:"state,omitempty"`
	MD         map[string]string `json:"md,omitempty"`
	// contains filtered or unexported fields
}

Node implement Entry interface.

func (*Node) Address

func (n *Node) Address() (network, addr string)

Address

func (*Node) BalanceName

func (n *Node) BalanceName() string

BalanceName get balance name

func (*Node) Client

func (n *Node) Client() network.Client

func (*Node) Equals

func (n *Node) Equals(e Entry) bool

Equals returns true if cmp contains the same data.

func (*Node) Metadata

func (n *Node) Metadata(key string) (v string)

Metadata get entry metadate

func (*Node) ModifyState

func (n *Node) ModifyState(state EntryState)

ModifyState use for modify entry state

func (*Node) SetClient

func (n *Node) SetClient(cli network.Client)

func (*Node) State

func (n *Node) State() EntryState

State return node state

func (*Node) String

func (n *Node) String() string

String returns the string form of an entry.

type Registry

type Registry interface {
	// NewEntry create entry,wait for register
	NewEntry(ctx context.Context, addr net.Addr) (err error)
	// Online set entry online status and update to store
	Online(ctx context.Context) (err error)
	// Offline set entry offline status and update to store
	Offline(ctx context.Context) (err error)
	// Close clean entry info
	Clean(ctx context.Context) (err error)
	// GetEntry get current node's Entry
	GetEntry() Entry
	// UpdateEntry
	UpdateEntry(ctx context.Context) (err error)
}

Registry use for netwrok service register entry

func NewRegistry

func NewRegistry(path string, store kvstore.Store, opts ...RegistryOption) Registry

type RegistryOption

type RegistryOption func(cc *RegistryOptions) RegistryOption

RegistryOption option define

func WithRegistryOptionCodec

func WithRegistryOptionCodec(v EntryCodec) RegistryOption

Codec use for encode entry.

func WithRegistryOptionFrameLogger

func WithRegistryOptionFrameLogger(v *zaplog.Logger) RegistryOption

frame log

func WithRegistryOptionNewEntry

func WithRegistryOptionNewEntry(v func(addr net.Addr) (_ Entry, err error)) RegistryOption

NewEntry create custom entry for registry

type RegistryOptions

type RegistryOptions struct {
	// NewEntry create custom entry for registry
	NewEntry func(addr net.Addr) (_ Entry, err error)
	// Codec use for encode entry.
	Codec EntryCodec
	// frame log
	FrameLogger *zaplog.Logger
}

func NewRegistryOptions

func NewRegistryOptions(opts ...RegistryOption) *RegistryOptions

NewRegistryOptions create options instance.

func (*RegistryOptions) ApplyOption

func (cc *RegistryOptions) ApplyOption(opts ...RegistryOption)

ApplyOption modify options

func (*RegistryOptions) GetSetOption

func (cc *RegistryOptions) GetSetOption(opt RegistryOption) RegistryOption

GetSetOption modify and get last option

func (*RegistryOptions) SetOption

func (cc *RegistryOptions) SetOption(opt RegistryOption)

SetOption modify options

Jump to

Keyboard shortcuts

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