commands/http: Cleaner URL formation in client
Matt Bell committed
Nov 3, 2014 at 23:48 UTC
33b0990a3ad0bf63333ea225924b1c7216477d1f
1 file changed
+6
-3
commands/http/client.go
+6
-3
@@ -11,7 +11,10 @@ import (
11
cmds "github.com/jbenet/go-ipfs/commands"
12
)
13
14
-const ApiPath = "/api/v0" // TODO: make configurable
14
+const (
15
+ ApiUrlFormat = "http://%s%s/%s"
16
+ ApiPath = "/api/v0" // TODO: make configurable
17
+)
18
19
// Client is the commands HTTP client interface.
20
type Client interface {
@@ -27,8 +30,8 @@ func NewClient(address string) Client {
30
}
31
32
func (c *client) Send(req cmds.Request) (cmds.Response, error) {
30
- url := "http://" + c.serverAddress + ApiPath
31
- url += "/" + strings.Join(req.Path(), "/")
33
+ path := strings.Join(req.Path(), "/")
34
+ url := fmt.Sprintf(ApiUrlFormat, c.serverAddress, ApiPath, path)
35
36
var userEncoding string
37
if enc, found := req.Option(cmds.EncShort); found {