From 48bd73c53025ed2df92493551998014b2adfb304 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 27 Oct 2014 17:31:08 -0700 Subject: [PATCH] commands/http: Made client load RPC host from config --- commands/http/client.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/commands/http/client.go b/commands/http/client.go index e51686d2e..61770df06 100644 --- a/commands/http/client.go +++ b/commands/http/client.go @@ -6,14 +6,26 @@ import ( "net/http" "strings" + ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" + manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net" + cmds "github.com/jbenet/go-ipfs/commands" ) const ApiPath = "/api/v0" func Send(req cmds.Request) (cmds.Response, error) { - // TODO: load RPC host from config - url := "http://localhost:8080" + ApiPath + addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API) + if err != nil { + return nil, err + } + + _, host, err := manet.DialArgs(addr) + if err != nil { + return nil, err + } + + url := "http://" + host + ApiPath url += "/" + strings.Join(req.Path(), "/") // TODO: support other encodings once we have multicodec to decode response