commands/http: Refactored API to a Client object that takes a string address
Matt Bell committed
Nov 3, 2014 at 23:42 UTC
5e5d534eb311527f8b20ff9e78f6c5a9c4277931
1 file changed
+13
-13
commands/http/client.go
+13
-13
@@ -8,26 +8,26 @@ import (
8
"net/http"
9
"strings"
10
11
- ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
12
- manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
13
-
11
cmds "github.com/jbenet/go-ipfs/commands"
12
)
13
14
const ApiPath = "/api/v0" // TODO: make configurable
15
19
-func Send(req cmds.Request) (cmds.Response, error) {
20
- addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API)
21
- if err != nil {
22
- return nil, err
23
- }
16
+// Client is the commands HTTP client interface.
17
+type Client interface {
18
+ Send(req cmds.Request) (cmds.Response, error)
19
+}
20
25
- _, host, err := manet.DialArgs(addr)
26
- if err != nil {
27
- return nil, err
28
- }
21
+type client struct {
22
+ serverAddress string
23
+}
24
+
25
+func NewClient(address string) Client {
26
+ return &client{address}
27
+}
28
30
- url := "http://" + host + ApiPath
29
+func (c *client) Send(req cmds.Request) (cmds.Response, error) {
30
+ url := "http://" + c.serverAddress + ApiPath
31
url += "/" + strings.Join(req.Path(), "/")
32
33
var userEncoding string