commands/http: Refactored API to a Client object that takes a string address
Matt Bell committed
Nov 3, 2014 at 23:42 UTC
283c175fc4a66ea39d314d457622ba654b2d4f87
1 file changed
+18
-1
cmd/ipfs2/main.go
+18
-1
@@ -6,6 +6,9 @@ import (
6
"os"
7
"runtime/pprof"
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
cmdsCli "github.com/jbenet/go-ipfs/commands/cli"
14
cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
@@ -133,7 +136,21 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
136
}
137
138
if (!found || !localBool) && daemon.Locked(req.Context().ConfigRoot) {
136
- res, err = cmdsHttp.Send(req)
139
+ addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API)
140
+ if err != nil {
141
+ fmt.Println(err)
142
+ os.Exit(1)
143
+ }
144
+
145
+ _, host, err := manet.DialArgs(addr)
146
+ if err != nil {
147
+ fmt.Println(err)
148
+ os.Exit(1)
149
+ }
150
+
151
+ client := cmdsHttp.NewClient(host)
152
+
153
+ res, err = client.Send(req)
154
if err != nil {
155
fmt.Println(err)
156
os.Exit(1)