Skip to content

Commit

Permalink
commands/http: Refactored API to a Client object that takes a string …
Browse files Browse the repository at this point in the history
…address
  • Loading branch information
mappum authored and jbenet committed Nov 4, 2014
1 parent 22a826a commit 7855c13
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/ipfs2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7855c13

Please sign in to comment.