Documentation ¶
Index ¶
- Variables
- type Backend
- type Event
- type InMemoryBackend
- func (s *InMemoryBackend) Delete(p *proxy.Proxy) error
- func (s *InMemoryBackend) Insert(p *proxy.Proxy) error
- func (s *InMemoryBackend) InsertOrUpdate(p *proxy.Proxy) (bool, error)
- func (s *InMemoryBackend) Iter(iter Iterator)
- func (s *InMemoryBackend) Len() uint
- func (s *InMemoryBackend) Search(ip net.IP) *proxy.Proxy
- func (s *InMemoryBackend) Select(opts ...storage.SelectOption) ([]*proxy.Proxy, error)
- func (s *InMemoryBackend) TopK(k int) []*proxy.Proxy
- func (s *InMemoryBackend) Update(newP *proxy.Proxy) error
- type InsertionWatcher
- type Iterator
- type NotifyBackend
- type Op
Constants ¶
This section is empty.
Variables ¶
var ( ErrProxyInvalid = errors.New("proxy is nil or score <= 0") ErrProxyDuplicated = errors.New("proxy is already in backend") ErrProxyDoesNotExists = errors.New("proxy doesn't exists") ErrProxyNoneAvailable = errors.New("proxy none available") )
Errors occur when using backend.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface { Insert(p *proxy.Proxy) error Update(newP *proxy.Proxy) error InsertOrUpdate(p *proxy.Proxy) (inserted bool, err error) Delete(p *proxy.Proxy) error Search(ip net.IP) *proxy.Proxy // Select returns proxies after filter with options Select(opts ...storage.SelectOption) ([]*proxy.Proxy, error) Len() uint // TopK returns the first K proxies order by score descend. // If k is equal to 0, return all proxies in the backend TopK(k int) []*proxy.Proxy Iter(iter Iterator) }
Backend is an interface that store and manipulate proxies
type Event ¶
type Event struct { Op Op // Backend operation that triggered the event. Pxy *proxy.Proxy // Related proxy. }
Event represents a single backend notification.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend is a simple local in memory backend.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend returns new InMemoryBackend with default configurations.
func (*InMemoryBackend) InsertOrUpdate ¶
func (s *InMemoryBackend) InsertOrUpdate(p *proxy.Proxy) (bool, error)
func (*InMemoryBackend) Iter ¶
func (s *InMemoryBackend) Iter(iter Iterator)
func (*InMemoryBackend) Len ¶
func (s *InMemoryBackend) Len() uint
func (*InMemoryBackend) Select ¶
func (s *InMemoryBackend) Select(opts ...storage.SelectOption) ([]*proxy.Proxy, error)
type InsertionWatcher ¶
type InsertionWatcher struct {
// contains filtered or unexported fields
}
InsertionWatcher only interested in the new proxy inserted event, and will notify when the proxy passed filtered if filters set.
func NewInsertionWatcher ¶
func NewInsertionWatcher(callback func(*proxy.Proxy), fn ...storage.Filter) *InsertionWatcher
func (*InsertionWatcher) Receipt ¶
func (w *InsertionWatcher) Receipt(obj interface{})
Receipt implements pubsub.Watcher interface with filters.
type Iterator ¶
Iterator is the function which will be call for each proxy in backend. It will stop when the iterator returns false.
type NotifyBackend ¶
NotifyBackend is an interface that notify when data changes in backend.
func WithNotifier ¶
func WithNotifier(backend Backend, notifier pubsub.Notifier) NotifyBackend
WithNotifier returns a notifiable backend with notifier