From 25a0aca7ddea2684be5c1895ad86896f9fc94b30 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 21 Aug 2020 09:23:01 +0100 Subject: [PATCH] Registry router fixes (#1961) * only cache routes if told to do so * Use roundrobin selector and retry in proxy * Update lookup to require service * Fix compile * Fix compile * Update * Update * rename query to lookup * Update router.go * Update --- dns.go | 60 ++++++++++++++++------------------------------------------ 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/dns.go b/dns.go index dfbd7b4..005d429 100644 --- a/dns.go +++ b/dns.go @@ -17,19 +17,17 @@ func NewRouter(opts ...router.Option) router.Router { if len(options.Network) == 0 { options.Network = "micro" } - return &dns{options, &table{options}} + return &dns{options} } type dns struct { options router.Options - table *table } func (d *dns) Init(opts ...router.Option) error { for _, o := range opts { o(&d.options) } - d.table.options = d.options return nil } @@ -38,50 +36,16 @@ func (d *dns) Options() router.Options { } func (d *dns) Table() router.Table { - return d.table -} - -func (d *dns) Lookup(opts ...router.QueryOption) ([]router.Route, error) { - return d.table.Query(opts...) -} - -func (d *dns) Watch(opts ...router.WatchOption) (router.Watcher, error) { - return nil, nil + return nil } func (d *dns) Close() error { return nil } -func (d *dns) String() string { - return "dns" -} - -type table struct { - options router.Options -} - -func (t *table) Create(router.Route) error { - return nil -} - -func (t *table) Delete(router.Route) error { - return nil -} - -func (t *table) Update(router.Route) error { - return nil -} - -func (t *table) List() ([]router.Route, error) { - return nil, nil -} - -func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) { - options := router.NewQuery(opts...) - +func (d *dns) Lookup(service string, opts ...router.LookupOption) ([]router.Route, error) { // check to see if we have the port provided in the service, e.g. go-micro-srv-foo:8000 - host, port, err := net.SplitHostPort(options.Service) + host, port, err := net.SplitHostPort(service) if err == nil { // lookup the service using A records ips, err := net.LookupHost(host) @@ -95,7 +59,7 @@ func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) { result := make([]router.Route, len(ips)) for i, ip := range ips { result[i] = router.Route{ - Service: options.Service, + Service: service, Address: fmt.Sprintf("%s:%d", ip, uint16(p)), } } @@ -104,7 +68,7 @@ func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) { // we didn't get the port so we'll lookup the service using SRV records. If we can't lookup the // service using the SRV record, we return the error. - _, nodes, err := net.LookupSRV(options.Service, "tcp", t.options.Network) + _, nodes, err := net.LookupSRV(service, "tcp", d.options.Network) if err != nil { return nil, err } @@ -113,10 +77,18 @@ func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) { result := make([]router.Route, len(nodes)) for i, n := range nodes { result[i] = router.Route{ - Service: options.Service, + Service: service, Address: fmt.Sprintf("%s:%d", n.Target, n.Port), - Network: t.options.Network, + Network: d.options.Network, } } return result, nil } + +func (d *dns) Watch(opts ...router.WatchOption) (router.Watcher, error) { + return nil, nil +} + +func (d *dns) String() string { + return "dns" +}