From d8dc713e2d73dd8fb534313312d2cdf645a06660 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 23 Sep 2019 17:50:53 +0100 Subject: [PATCH] Fix the http resolver to use micro.mu url --- network/resolver/http/http.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/network/resolver/http/http.go b/network/resolver/http/http.go index 055662a5..a407c693 100644 --- a/network/resolver/http/http.go +++ b/network/resolver/http/http.go @@ -17,11 +17,19 @@ type Resolver struct { // Path sets the path to lookup. Defaults to /network Path string + + // Host url to use for the query + Host string +} + +type Response struct { + Nodes []*resolver.Record `json:"nodes,omitempty"` } // Resolve assumes ID is a domain which can be converted to a http://name/network request func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) { - proto := "http" + proto := "https" + host := "micro.mu" path := "/network" if len(r.Proto) > 0 { @@ -32,11 +40,18 @@ func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) { path = r.Path } + if len(r.Host) > 0 { + host = r.Host + } + uri := &url.URL{ Scheme: proto, Path: path, - Host: name, + Host: host, } + q := uri.Query() + q.Set("name", name) + uri.RawQuery = q.Encode() rsp, err := http.Get(uri.String()) if err != nil { @@ -50,11 +65,11 @@ func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) { } // encoding format is assumed to be json - var records []*resolver.Record + var response *Response - if err := json.Unmarshal(b, &records); err != nil { + if err := json.Unmarshal(b, &response); err != nil { return nil, err } - return records, nil + return response.Nodes, nil }