2019-06-06 18:37:40 +03:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/registry"
|
|
|
|
"github.com/micro/go-micro/registry/gossip"
|
|
|
|
)
|
|
|
|
|
|
|
|
type router struct {
|
|
|
|
opts Options
|
|
|
|
goss registry.Registry
|
2019-06-07 15:29:09 +03:00
|
|
|
t Table
|
2019-06-06 18:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func newRouter(opts ...Option) Router {
|
2019-06-07 01:29:24 +03:00
|
|
|
// TODO: figure out how to supply gossip registry options
|
2019-06-06 18:37:40 +03:00
|
|
|
r := &router{
|
2019-06-07 01:29:24 +03:00
|
|
|
goss: gossip.NewRegistry(),
|
|
|
|
t: NewTable(),
|
2019-06-06 18:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&r.opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:29:24 +03:00
|
|
|
// Init initializes router with given options
|
2019-06-06 18:37:40 +03:00
|
|
|
func (r *router) Init(opts ...Option) error {
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&r.opts)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:29:24 +03:00
|
|
|
// Options returns router options
|
2019-06-06 18:37:40 +03:00
|
|
|
func (r *router) Options() Options {
|
|
|
|
return r.opts
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:29:24 +03:00
|
|
|
// Add adds new entry into routing table with given options.
|
|
|
|
// It returns error if the entry could not be added.
|
|
|
|
func (r *router) Add(e *Entry, opts ...RouteOption) error {
|
2019-06-06 18:37:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:29:24 +03:00
|
|
|
// Remove removes entry from the routing table.
|
|
|
|
// It returns error if either the entry could not be removed or it does not exist.
|
|
|
|
func (r *router) Remove(e *Entry) error {
|
2019-06-06 18:37:40 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:29:24 +03:00
|
|
|
// Update updates an entry in the router's routing table
|
|
|
|
// It returns error if the entry was not found or it failed to be updated.
|
|
|
|
func (r *router) Update(e *Entry) error {
|
|
|
|
return nil
|
2019-06-06 18:37:40 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 01:29:24 +03:00
|
|
|
// Lookup makes a query lookup and returns all matching entries
|
|
|
|
func (r *router) Lookup(q Query) ([]*Entry, error) {
|
2019-06-06 18:37:40 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:29:24 +03:00
|
|
|
// Table returns routing table
|
2019-06-07 15:29:09 +03:00
|
|
|
func (r *router) Table() Table {
|
2019-06-07 01:29:24 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Address returns router's network address
|
|
|
|
func (r *router) Address() string {
|
2019-06-07 15:29:09 +03:00
|
|
|
return r.opts.Address
|
2019-06-07 01:29:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// String prints debugging information about router
|
2019-06-06 18:37:40 +03:00
|
|
|
func (r *router) String() string {
|
|
|
|
return ""
|
|
|
|
}
|