Documentation ¶
Index ¶
- Variables
- func InstallDiscoveryOptionsWatchDog(dog func(cc *DiscoveryOptions))
- func InstallRegistryOptionsWatchDog(dog func(cc *RegistryOptions))
- type Client
- type Discovery
- type DiscoveryOption
- type DiscoveryOptions
- type Entries
- type Entry
- type EntryCodec
- type EntryState
- type NoOpDiscovery
- func (NoOpDiscovery) Close(ctx context.Context)
- func (NoOpDiscovery) GetAll(ctx context.Context) (all Entries, err error)
- func (NoOpDiscovery) Watch(ctx context.Context) (changes <-chan Entries, err error)
- func (NoOpDiscovery) WatchEventNotify(ctx context.Context, eventNotify func(Entries)) (err error)
- type NoOpRegistry
- func (NoOpRegistry) Clean(ctx context.Context) (err error)
- func (NoOpRegistry) GetEntry() Entry
- func (NoOpRegistry) NewEntry(ctx context.Context, addr net.Addr) (err error)
- func (NoOpRegistry) Offline(ctx context.Context) (err error)
- func (NoOpRegistry) Online(ctx context.Context) (err error)
- func (NoOpRegistry) UpdateEntry(ctx context.Context) (err error)
- type Node
- func (n *Node) Address() (network, addr string)
- func (n *Node) BalanceName() string
- func (n *Node) Client() network.Client
- func (n *Node) Equals(e Entry) bool
- func (n *Node) Metadata(key string) (v string)
- func (n *Node) ModifyState(state EntryState)
- func (n *Node) SetClient(cli network.Client)
- func (n *Node) State() EntryState
- func (n *Node) String() string
- type Registry
- type RegistryOption
- type RegistryOptions
Constants ¶
This section is empty.
Variables ¶
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 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.
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) 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) ModifyState ¶
func (n *Node) ModifyState(state EntryState)
ModifyState use for modify entry state
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