Redefeind interfaces; Added better modelled data strauctures
Router interface has been redefined which fits better with what we are looking for. Routing table now offers a comprehensive set of information about its entries which will make up for rich queries in the future Query interface has been defined to enable current basic and more advanced queries in the future.
This commit is contained in:
@@ -2,25 +2,32 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/micro/go-micro/registry"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultRouter returns default micro router
|
||||
DefaultRouter = NewRouter()
|
||||
)
|
||||
|
||||
// Router is micro network router
|
||||
type Router interface {
|
||||
// Initi initializes Router with options
|
||||
Init(...Option) error
|
||||
// Options returns Router options
|
||||
Options() Options
|
||||
// AddRoute adds new service route
|
||||
AddRoute(*Route, ...RouteOption) error
|
||||
// RemoveRoute removes service route
|
||||
RemoveRoute(*Route) error
|
||||
// GetRoute returns list of routes for service
|
||||
GetRoute(*Service) ([]*Route, error)
|
||||
// List returns all routes
|
||||
List() ([]*Route, error)
|
||||
// Add adds new entry into routing table
|
||||
Add(*Entry, ...RouteOption) error
|
||||
// Remove removes entry from the routing table
|
||||
Remove(*Entry) error
|
||||
// Update updates entry in the routing table
|
||||
Update(*Entry) error
|
||||
// Lookup queries the routing table and returns matching entries
|
||||
Lookup(Query) ([]*Entry, error)
|
||||
// Table returns routing table
|
||||
Table() *Table
|
||||
// Address is Router adddress
|
||||
Address() string
|
||||
// String implemens fmt.Stringer interface
|
||||
String() string
|
||||
}
|
||||
@@ -28,22 +35,21 @@ type Router interface {
|
||||
// Option used by the Router
|
||||
type Option func(*Options)
|
||||
|
||||
var (
|
||||
DefaultRouter = NewRouter()
|
||||
// RouteOption is used by Router for adding routing table entries
|
||||
type RouteOption func(*RouteOptions)
|
||||
|
||||
// Not found error when Get is called
|
||||
ErrNotFound = errors.New("route not found")
|
||||
)
|
||||
// QueryOption is used to defined routing table lookup query
|
||||
type QueryOption func(*QueryOptions)
|
||||
|
||||
// NewRouter creates new Router and returns it
|
||||
func NewRouter(opts ...Option) Router {
|
||||
// set Registry to DefaultRegistry
|
||||
opt := Options{
|
||||
// router registry to DefaultRegistry
|
||||
ropts := Options{
|
||||
Registry: registry.DefaultRegistry,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&opt)
|
||||
o(&ropts)
|
||||
}
|
||||
|
||||
return newRouter(opts...)
|
||||
|
||||
Reference in New Issue
Block a user