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:
Milos Gajdos
2019-06-06 23:29:24 +01:00
parent 08da7c1283
commit ee8b6b3114
7 changed files with 206 additions and 51 deletions

View File

@@ -2,7 +2,6 @@ package router
import (
"context"
"time"
"github.com/micro/go-micro/registry"
)
@@ -15,17 +14,33 @@ type Options struct {
Context context.Context
}
// RouteOption allows to soecify routing table options
type RouteOption struct {
// TTL defines route entry lifetime
TTL time.Duration
// COntext allows to specify other arbitrary options
Context context.Context
}
// Registry is local registry
// Registry allows to set local service registry
func Registry(r registry.Registry) Option {
return func(o *Options) {
o.Registry = r
}
}
// RouteOptions allows to specify routing table options
type RouteOptions struct {
// NetID is network ID
NetID string
// Metric is route metric
Metric int
// COntext allows to specify other arbitrary options
Context context.Context
}
// NetID allows to set micro network ID
func NetID(id string) RouteOption {
return func(o *RouteOptions) {
o.NetID = id
}
}
// Metric allows to set route cost metric
func Metric(m int) RouteOption {
return func(o *RouteOptions) {
o.Metric = m
}
}