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:
70
router/query.go
Normal file
70
router/query.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package router
|
||||
|
||||
// Policy defines query policy
|
||||
type QueryPolicy int
|
||||
|
||||
const (
|
||||
// DiscardNoRoute discards query when no rout is found
|
||||
DiscardNoRoute QueryPolicy = iota
|
||||
// ClosestMatch returns closest match to query
|
||||
ClosestMatch
|
||||
)
|
||||
|
||||
// QueryOptions allow to define routing table query options
|
||||
type QueryOptions struct {
|
||||
// Route allows to set route options
|
||||
Route *RouteOptions
|
||||
// Service is micro service name
|
||||
Service string
|
||||
// Policy defines query lookup policy
|
||||
Policy QueryPolicy
|
||||
}
|
||||
|
||||
// Route allows to set the route query options
|
||||
func Route(r *RouteOptions) QueryOption {
|
||||
return func(o *QueryOptions) {
|
||||
o.Route = r
|
||||
}
|
||||
}
|
||||
|
||||
// Service allows to set the service name in routing query
|
||||
func Service(s string) QueryOption {
|
||||
return func(o *QueryOptions) {
|
||||
o.Service = s
|
||||
}
|
||||
}
|
||||
|
||||
// Policy allows to define query lookup policy
|
||||
func Policy(p QueryPolicy) QueryOption {
|
||||
return func(o *QueryOptions) {
|
||||
o.Policy = p
|
||||
}
|
||||
}
|
||||
|
||||
// Query defines routing table query
|
||||
type Query interface {
|
||||
// Options returns query options
|
||||
Options() QueryOptions
|
||||
}
|
||||
|
||||
type query struct {
|
||||
opts QueryOptions
|
||||
}
|
||||
|
||||
// NewQuery creates new query and returns it
|
||||
func NewQuery(opts ...QueryOption) Query {
|
||||
qopts := QueryOptions{}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&qopts)
|
||||
}
|
||||
|
||||
return &query{
|
||||
opts: qopts,
|
||||
}
|
||||
}
|
||||
|
||||
// Options returns query options
|
||||
func (q *query) Options() QueryOptions {
|
||||
return q.opts
|
||||
}
|
||||
Reference in New Issue
Block a user