backend

package
v0.0.0-...-6e90328 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Delete

func (s *InMemoryBackend) Delete(p *proxy.Proxy) error

func (*InMemoryBackend) Insert

func (s *InMemoryBackend) Insert(p *proxy.Proxy) error

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) Search

func (s *InMemoryBackend) Search(ip net.IP) *proxy.Proxy

func (*InMemoryBackend) Select

func (s *InMemoryBackend) Select(opts ...storage.SelectOption) ([]*proxy.Proxy, error)

func (*InMemoryBackend) TopK

func (s *InMemoryBackend) TopK(k int) []*proxy.Proxy

func (*InMemoryBackend) Update

func (s *InMemoryBackend) Update(newP *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

type Iterator func(pxy *proxy.Proxy) bool

Iterator is the function which will be call for each proxy in backend. It will stop when the iterator returns false.

type NotifyBackend

type NotifyBackend interface {
	pubsub.Notifier
	Backend
}

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

type Op

type Op uint32

Op describes a set of backend operations.

const (
	Insert Op = iota
	Update
	Delete
)

These are the generalized backend operations that can trigger a notification.

Jump to

Keyboard shortcuts

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