From 283c175fc4a66ea39d314d457622ba654b2d4f87 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 3 Nov 2014 23:42:05 -0800 Subject: [PATCH] commands/http: Refactored API to a Client object that takes a string address --- cmd/ipfs2/main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/ipfs2/main.go b/cmd/ipfs2/main.go index 64e6a51b6..e7ea3fa36 100644 --- a/cmd/ipfs2/main.go +++ b/cmd/ipfs2/main.go @@ -6,6 +6,9 @@ import ( "os" "runtime/pprof" + 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" cmdsCli "github.com/jbenet/go-ipfs/commands/cli" cmdsHttp "github.com/jbenet/go-ipfs/commands/http" @@ -133,7 +136,21 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response { } if (!found || !localBool) && daemon.Locked(req.Context().ConfigRoot) { - res, err = cmdsHttp.Send(req) + addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + _, host, err := manet.DialArgs(addr) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + client := cmdsHttp.NewClient(host) + + res, err = client.Send(req) if err != nil { fmt.Println(err) os.Exit(1)