mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-29 21:47:44 +02:00
Redefined and polished some interfaces and data structures.
This commit is contained in:
@@ -3,12 +3,34 @@ package router
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrRouteNotFound is returned when no rout was found
|
||||
// DefaultRouter returns default micro router
|
||||
DefaultTable = NewTable()
|
||||
// ErrRouteNotFound is returned when no route was found
|
||||
ErrRouteNotFound = errors.New("route not found")
|
||||
// ErrDuplicateRoute is return when route already exists
|
||||
ErrDuplicateRoute = errors.New("duplicate route")
|
||||
)
|
||||
|
||||
// Table is routing table
|
||||
type Table interface {
|
||||
// Add adds new route to the table
|
||||
Add(*Entry) error
|
||||
// Remove removes route from the table
|
||||
Remove(*Entry) error
|
||||
// Update updates route in the table
|
||||
Update(*Entry) error
|
||||
// Lookup looks up routes in the table
|
||||
Lookup(Query) ([]*Entry, error)
|
||||
// Size returns the size of the table
|
||||
Size() int
|
||||
// String prints the routing table
|
||||
String() string
|
||||
}
|
||||
|
||||
// Entry is micro network routing table entry
|
||||
type Entry struct {
|
||||
// DestAddr is destination address
|
||||
DestAddr string
|
||||
// NetID is micro network ID
|
||||
NetID string
|
||||
// Hop is the next route hop
|
||||
@@ -17,42 +39,46 @@ type Entry struct {
|
||||
Metric int
|
||||
}
|
||||
|
||||
// Table is routing table
|
||||
// table is routing table
|
||||
// It maps service name to routes
|
||||
type Table struct {
|
||||
type table struct {
|
||||
// m stores routing table map
|
||||
m map[string][]Entry
|
||||
}
|
||||
|
||||
// NewTable creates new routing table and returns it
|
||||
func NewTable() *Table {
|
||||
return &Table{
|
||||
func NewTable() Table {
|
||||
return &table{
|
||||
m: make(map[string][]Entry),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Define lookup query interface
|
||||
// Lookup looks up entry in the routing table
|
||||
func (t *Table) Lookup() (*Entry, error) {
|
||||
return nil, nil
|
||||
// Add adds new routing entry
|
||||
func (t *table) Add(e *Entry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove removes entry from the routing table
|
||||
func (t *Table) Remove(e *Entry) error {
|
||||
func (t *table) Remove(e *Entry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates routin entry
|
||||
func (t *Table) Update(e *Entry) error {
|
||||
func (t *table) Update(e *Entry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Lookup looks up entry in the routing table
|
||||
func (t *table) Lookup(q Query) ([]*Entry, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Size returns the size of the routing table
|
||||
func (t *Table) Size() int {
|
||||
return 0
|
||||
func (t *table) Size() int {
|
||||
return len(t.m)
|
||||
}
|
||||
|
||||
// String returns text representation of routing table
|
||||
func (t *Table) String() string {
|
||||
func (t *table) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user