watcher

package
v0.1.27 Latest Latest
Warning

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

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

README

watcher

  1. watcher组件是对file, etcd, 等其他组件的抽象
  2. watcher组件会更新全局的配置
  3. watcher组件管理所有的watcher的实现

Documentation

Index

Constants

View Source
const Name = "watcher"

Variables

This section is empty.

Functions

func GetWatchers

func GetWatchers() map[string][]func(name string, r *Response) error

func KeyToDot

func KeyToDot(prefix ...string) string

KeyToDot /projectName/foo/bar --> projectName.foo.bar

func RegisterFactory

func RegisterFactory(name string, w Factory)

RegisterFactory 注册watcher build factory

func Watch

func Watch(name string, callback func(name string, r *Response) error)

Types

type Cfg

type Cfg struct {
	Driver    string                 `json:"driver"`
	DriverCfg map[string]interface{} `json:"driver_config"`
	SkipNull  bool                   `json:"skip_null"`

	// Projects 需要watcher的项目
	Projects []string `json:"projects"`
}

func DefaultCfg

func DefaultCfg() Cfg

type Factory

type Factory = func(cfg config.CfgMap) (Watcher, error)

func GetFactory

func GetFactory(names ...string) Factory

type Opt

type Opt func(*options)

type Response

type Response struct {
	Type    string
	Event   event.EventType
	Key     string
	Value   []byte
	Version int64
}

func (*Response) Decode

func (t *Response) Decode(c interface{}) (err error)

func (*Response) OnDelete

func (t *Response) OnDelete(fn func())

func (*Response) OnPut

func (t *Response) OnPut(fn func())

type WatchHandler

type WatchHandler = func(name string, r *Response) error

type Watcher

type Watcher interface {
	Init()
	Close()
	Get(ctx context.Context, key string, opts ...Opt) ([]*Response, error)
	GetCallback(ctx context.Context, key string, fn func(resp *Response), opts ...Opt) error
	Watch(ctx context.Context, key string, opts ...Opt) <-chan *Response
	WatchCallback(ctx context.Context, key string, fn func(resp *Response), opts ...Opt)
}

Watcher ...

Directories

Path Synopsis
watcher_driver

Jump to

Keyboard shortcuts

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