Big refactor. New Registry watchers. New options. New names.

This commit is contained in:
Milos Gajdos
2019-06-12 22:30:42 +01:00
parent 338e0fdf18
commit 95fc625e99
8 changed files with 346 additions and 90 deletions

View File

@@ -12,18 +12,25 @@ const (
// QueryOptions allow to define routing table query options
type QueryOptions struct {
// Route allows to set route options
RouteOptions *RouteOptions
// DestAddr defines destination address
DestAddr string
// NetworkAddress defines network address
Network string
// Policy defines query lookup policy
Policy LookupPolicy
// Count defines max number of results to return
Count int
}
// QueryRouteOpts allows to set the route query options
func QueryRouteOptons(r *RouteOptions) QueryOption {
// QueryDestAddr sets query destination address
func QueryDestAddr(a string) QueryOption {
return func(o *QueryOptions) {
o.RouteOptions = r
o.DestAddr = a
}
}
// QueryNetwork sets query network address
func QueryNetwork(a string) QueryOption {
return func(o *QueryOptions) {
o.Network = a
}
}
@@ -34,13 +41,6 @@ func QueryPolicy(p LookupPolicy) QueryOption {
}
}
// QueryCount allows to set max results to return
func QueryCount(c int) QueryOption {
return func(o *QueryOptions) {
o.Count = c
}
}
// Query defines routing table query
type Query interface {
// Options returns query options
@@ -53,7 +53,12 @@ type query struct {
// NewQuery creates new query and returns it
func NewQuery(opts ...QueryOption) Query {
qopts := QueryOptions{}
// default options
qopts := QueryOptions{
DestAddr: "*",
Network: "*",
Policy: DiscardNoRoute,
}
for _, o := range opts {
o(&qopts)