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