2019-06-06 18:37:40 +03:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2019-06-07 19:20:22 +03:00
|
|
|
"github.com/google/uuid"
|
2019-06-06 18:37:40 +03:00
|
|
|
"github.com/micro/go-micro/registry"
|
|
|
|
"github.com/micro/go-micro/registry/gossip"
|
|
|
|
)
|
|
|
|
|
|
|
|
type router struct {
|
2019-06-07 19:20:22 +03:00
|
|
|
opts Options
|
|
|
|
goss registry.Registry
|
|
|
|
table Table
|
|
|
|
id uuid.UUID
|
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 19:20:22 +03:00
|
|
|
goss: gossip.NewRegistry(),
|
|
|
|
table: NewTable(),
|
|
|
|
id: uuid.New(),
|
2019-06-06 18:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&r.opts)
|
|
|
|
}
|
|
|
|
|
2019-06-07 19:20:22 +03:00
|
|
|
// TODO: need to start some gossip.Registry watch here
|
|
|
|
|
2019-06-06 18:37:40 +03:00
|
|
|
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 19:20:22 +03:00
|
|
|
return r.table
|
|
|
|
}
|
|
|
|
|
|
|
|
// Network returns router's micro network
|
|
|
|
func (r *router) Network() string {
|
|
|
|
return r.opts.Network
|
2019-06-07 01:29:24 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 19:20:22 +03:00
|
|
|
// Address returns router's bind address
|
2019-06-07 01:29:24 +03:00
|
|
|
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 ""
|
|
|
|
}
|