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