2019-07-25 23:19:05 +01:00
|
|
|
package router
|
2019-06-18 18:33:05 +01:00
|
|
|
|
2019-06-13 23:28:47 +02:00
|
|
|
// QueryOption sets routing table query options
|
2019-06-13 12:09:49 +01:00
|
|
|
type QueryOption func(*QueryOptions)
|
|
|
|
|
2019-06-13 23:28:47 +02:00
|
|
|
// QueryOptions are routing table query options
|
2020-08-14 23:51:52 +01:00
|
|
|
// TODO replace with Filter(Route) bool
|
2019-06-06 23:29:24 +01:00
|
|
|
type QueryOptions struct {
|
2019-07-09 15:45:42 +01:00
|
|
|
// Service is destination service name
|
|
|
|
Service string
|
2019-10-09 17:13:52 +01:00
|
|
|
// Address of the service
|
|
|
|
Address string
|
2019-07-09 15:45:42 +01:00
|
|
|
// Gateway is route gateway
|
|
|
|
Gateway string
|
2019-06-19 21:22:14 +01:00
|
|
|
// Network is network address
|
2019-06-12 22:30:42 +01:00
|
|
|
Network string
|
2019-08-27 23:08:35 +01:00
|
|
|
// Router is router id
|
|
|
|
Router string
|
2020-08-14 23:51:52 +01:00
|
|
|
// Link to query
|
|
|
|
Link string
|
2019-06-06 23:29:24 +01:00
|
|
|
}
|
|
|
|
|
2019-08-27 23:08:35 +01:00
|
|
|
// QueryService sets service to query
|
2019-07-09 15:45:42 +01:00
|
|
|
func QueryService(s string) QueryOption {
|
2019-06-06 23:29:24 +01:00
|
|
|
return func(o *QueryOptions) {
|
2019-07-09 15:45:42 +01:00
|
|
|
o.Service = s
|
2019-06-06 23:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 17:13:52 +01:00
|
|
|
// QueryAddress sets service to query
|
|
|
|
func QueryAddress(a string) QueryOption {
|
|
|
|
return func(o *QueryOptions) {
|
|
|
|
o.Address = a
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 23:08:35 +01:00
|
|
|
// QueryGateway sets gateway address to query
|
2019-07-09 15:45:42 +01:00
|
|
|
func QueryGateway(g string) QueryOption {
|
2019-06-06 23:29:24 +01:00
|
|
|
return func(o *QueryOptions) {
|
2019-07-09 15:45:42 +01:00
|
|
|
o.Gateway = g
|
2019-06-06 23:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 23:08:35 +01:00
|
|
|
// QueryNetwork sets network name to query
|
2019-07-09 15:45:42 +01:00
|
|
|
func QueryNetwork(n string) QueryOption {
|
2019-06-16 23:09:59 +01:00
|
|
|
return func(o *QueryOptions) {
|
2019-07-09 15:45:42 +01:00
|
|
|
o.Network = n
|
2019-06-19 21:22:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 23:08:35 +01:00
|
|
|
// QueryRouter sets router id to query
|
|
|
|
func QueryRouter(r string) QueryOption {
|
|
|
|
return func(o *QueryOptions) {
|
|
|
|
o.Router = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-14 23:51:52 +01:00
|
|
|
// QueryLink sets the link to query
|
|
|
|
func QueryLink(link string) QueryOption {
|
2020-01-16 12:48:36 +00:00
|
|
|
return func(o *QueryOptions) {
|
2020-08-14 23:51:52 +01:00
|
|
|
o.Link = link
|
2020-01-16 12:48:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:24 +01:00
|
|
|
// NewQuery creates new query and returns it
|
2019-10-09 17:13:52 +01:00
|
|
|
func NewQuery(opts ...QueryOption) QueryOptions {
|
2019-06-12 22:30:42 +01:00
|
|
|
// default options
|
2020-10-16 09:38:57 +03:00
|
|
|
options := QueryOptions{
|
2020-08-14 23:51:52 +01:00
|
|
|
Service: "*",
|
|
|
|
Address: "*",
|
|
|
|
Gateway: "*",
|
|
|
|
Network: "*",
|
|
|
|
Router: "*",
|
|
|
|
Link: DefaultLink,
|
2019-06-12 22:30:42 +01:00
|
|
|
}
|
2019-06-06 23:29:24 +01:00
|
|
|
|
|
|
|
for _, o := range opts {
|
2020-10-16 09:38:57 +03:00
|
|
|
o(&options)
|
2019-06-06 23:29:24 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
return options
|
2019-06-06 23:29:24 +01:00
|
|
|
}
|