2019-06-07 01:29:24 +03:00
|
|
|
package router
|
|
|
|
|
2019-06-07 19:20:22 +03:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
2019-06-07 01:29:24 +03:00
|
|
|
|
|
|
|
var (
|
2019-06-13 14:09:49 +03:00
|
|
|
// ErrRouteNotFound is returned when no route was found in the routing table
|
2019-06-07 01:29:24 +03:00
|
|
|
ErrRouteNotFound = errors.New("route not found")
|
2019-06-13 14:09:49 +03:00
|
|
|
// ErrDuplicateRoute is returned when the route already exists
|
2019-06-07 15:29:09 +03:00
|
|
|
ErrDuplicateRoute = errors.New("duplicate route")
|
2019-06-07 01:29:24 +03:00
|
|
|
)
|
|
|
|
|
2019-06-13 14:09:49 +03:00
|
|
|
// Table defines routing table interface
|
2019-06-07 15:29:09 +03:00
|
|
|
type Table interface {
|
2019-06-13 14:09:49 +03:00
|
|
|
// Init initializes the router with options
|
|
|
|
Init(...TableOption) error
|
|
|
|
// Options returns the router options
|
|
|
|
Options() TableOptions
|
|
|
|
// Add adds new route to the routing table
|
2019-06-10 15:34:23 +03:00
|
|
|
Add(Route) error
|
2019-06-13 14:09:49 +03:00
|
|
|
// Remove removes existing route from the routing table
|
2019-06-10 15:34:23 +03:00
|
|
|
Remove(Route) error
|
2019-06-13 14:09:49 +03:00
|
|
|
// Update updates route in the routing table
|
2019-06-13 00:30:42 +03:00
|
|
|
Update(Route) error
|
2019-06-13 14:09:49 +03:00
|
|
|
// Lookup looks up routes in the routing table and returns them
|
2019-06-10 15:34:23 +03:00
|
|
|
Lookup(Query) ([]Route, error)
|
2019-06-13 14:09:49 +03:00
|
|
|
// Watch returns a watcher which allows to track updates to the routing table
|
2019-06-12 01:59:25 +03:00
|
|
|
Watch(opts ...WatchOption) (Watcher, error)
|
2019-06-13 14:09:49 +03:00
|
|
|
// Size returns the size of the routing table
|
2019-06-07 15:29:09 +03:00
|
|
|
Size() int
|
|
|
|
// String prints the routing table
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2019-06-13 14:09:49 +03:00
|
|
|
// TableOption used by the routing table
|
|
|
|
type TableOption func(*TableOptions)
|
2019-06-07 01:29:24 +03:00
|
|
|
|
|
|
|
// NewTable creates new routing table and returns it
|
2019-06-13 14:09:49 +03:00
|
|
|
func NewTable(opts ...TableOption) Table {
|
|
|
|
return newTable(opts...)
|
2019-06-10 15:34:23 +03:00
|
|
|
}
|