@cryptotaxi247 / kubo / commits / 48bd73c53

commands/http: Made client load RPC host from config

Matt Bell committed Oct 27, 2014 at 17:31 UTC 48bd73c53025ed2df92493551998014b2adfb304
1 file changed +14 -2
commands/http/client.go
+14 -2
@@ -6,14 +6,26 @@ import (
6 "net/http"
7 "strings"
8
9 + ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
10 + manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
11 +
12 cmds "github.com/jbenet/go-ipfs/commands"
13 )
14
15 const ApiPath = "/api/v0"
16
17 func Send(req cmds.Request) (cmds.Response, error) {
15 - // TODO: load RPC host from config
16 - url := "http://localhost:8080" + ApiPath
18 + addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API)
19 + if err != nil {
20 + return nil, err
21 + }
22 +
23 + _, host, err := manet.DialArgs(addr)
24 + if err != nil {
25 + return nil, err
26 + }
27 +
28 + url := "http://" + host + ApiPath
29 url += "/" + strings.Join(req.Path(), "/")
30
31 // TODO: support other encodings once we have multicodec to decode response