@cryptotaxi247 / kubo / commits / 1c07bed90

Export (*HttpApi).request to enable building custom requests

This commit was moved from ipfs/go-ipfs-http-client@8c9ed7dbc284b4d112f6805914a43e63f234df78

Edgar Lee committed Apr 1, 2019 at 17:13 UTC 1c07bed90465210c27dba3cda850913cf397b5c5
12 files changed +46 -46
client/httpapi/api.go
+1 -1
@@ -138,7 +138,7 @@ func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error)
138 return &subApi, nil
139 }
140
141 -func (api *HttpApi) request(command string, args ...string) *RequestBuilder {
141 +func (api *HttpApi) Request(command string, args ...string) *RequestBuilder {
142 return &RequestBuilder{
143 command: command,
144 args: args,
client/httpapi/apifile.go
+3 -3
@@ -29,7 +29,7 @@ func (api *UnixfsAPI) Get(ctx context.Context, p iface.Path) (files.Node, error)
29 Type string
30 Size int64 // unixfs size
31 }
32 - err := api.core().request("files/stat", p.String()).Exec(ctx, &stat)
32 + err := api.core().Request("files/stat", p.String()).Exec(ctx, &stat)
33 if err != nil {
34 return nil, err
35 }
@@ -59,7 +59,7 @@ func (f *apiFile) reset() error {
59 _ = f.r.Cancel()
60 f.r = nil
61 }
62 - req := f.core.request("cat", f.path.String())
62 + req := f.core.Request("cat", f.path.String())
63 if f.at != 0 {
64 req.Option("offset", f.at)
65 }
@@ -225,7 +225,7 @@ func (d *apiDir) Entries() files.DirIterator {
225 }
226
227 func (api *UnixfsAPI) getDir(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
228 - resp, err := api.core().request("ls", p.String()).
228 + resp, err := api.core().Request("ls", p.String()).
229 Option("resolve-size", true).
230 Option("stream", true).Send(ctx)
231
client/httpapi/block.go
+4 -4
@@ -41,7 +41,7 @@ func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockP
41 return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
42 }
43
44 - req := api.core().request("block/put").
44 + req := api.core().Request("block/put").
45 Option("mhtype", mht).
46 Option("mhlen", options.MhLength).
47 Option("format", options.Codec).
@@ -61,7 +61,7 @@ func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockP
61 }
62
63 func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
64 - resp, err := api.core().request("block/get", p.String()).Send(ctx)
64 + resp, err := api.core().Request("block/get", p.String()).Send(ctx)
65 if err != nil {
66 return nil, err
67 }
@@ -90,7 +90,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockR
90 Error string `json:",omitempty"`
91 }{}
92
93 - req := api.core().request("block/rm").
93 + req := api.core().Request("block/rm").
94 Option("force", options.Force).
95 Arguments(p.String())
96
@@ -107,7 +107,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockR
107
108 func (api *BlockAPI) Stat(ctx context.Context, p iface.Path) (iface.BlockStat, error) {
109 var out blockStat
110 - err := api.core().request("block/stat", p.String()).Exec(ctx, &out)
110 + err := api.core().Request("block/stat", p.String()).Exec(ctx, &out)
111 if err != nil {
112 return nil, err
113 }
client/httpapi/dht.go
+3 -3
@@ -18,7 +18,7 @@ func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peerstore.PeerInfo,
18 Type notif.QueryEventType
19 Responses []peerstore.PeerInfo
20 }
21 - resp, err := api.core().request("dht/findpeer", p.Pretty()).Send(ctx)
21 + resp, err := api.core().Request("dht/findpeer", p.Pretty()).Send(ctx)
22 if err != nil {
23 return peerstore.PeerInfo{}, err
24 }
@@ -48,7 +48,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
48 return nil, err
49 }
50
51 - resp, err := api.core().request("dht/findprovs", rp.Cid().String()).
51 + resp, err := api.core().Request("dht/findprovs", rp.Cid().String()).
52 Option("num-providers", options.NumProviders).
53 Send(ctx)
54 if err != nil {
@@ -104,7 +104,7 @@ func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.Dht
104 return err
105 }
106
107 - return api.core().request("dht/provide", rp.Cid().String()).
107 + return api.core().Request("dht/provide", rp.Cid().String()).
108 Option("recursive", options.Recursive).
109 Exec(ctx, nil)
110 }
client/httpapi/key.go
+5 -5
@@ -38,7 +38,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
38 }
39
40 var out keyOutput
41 - err = api.core().request("key/gen", name).
41 + err = api.core().Request("key/gen", name).
42 Option("type", options.Algorithm).
43 Option("size", options.Size).
44 Exec(ctx, &out)
@@ -61,7 +61,7 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o
61 Id string
62 Overwrite bool
63 }
64 - err = api.core().request("key/rename", oldName, newName).
64 + err = api.core().Request("key/rename", oldName, newName).
65 Option("force", options.Force).
66 Exec(ctx, &out)
67 if err != nil {
@@ -75,7 +75,7 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o
75
76 func (api *KeyAPI) List(ctx context.Context) ([]iface.Key, error) {
77 var out struct{ Keys []*keyOutput }
78 - if err := api.core().request("key/list").Exec(ctx, &out); err != nil {
78 + if err := api.core().Request("key/list").Exec(ctx, &out); err != nil {
79 return nil, err
80 }
81
@@ -94,7 +94,7 @@ func (api *KeyAPI) List(ctx context.Context) ([]iface.Key, error) {
94
95 func (api *KeyAPI) Self(ctx context.Context) (iface.Key, error) {
96 var id struct{ ID string }
97 - if err := api.core().request("id").Exec(ctx, &id); err != nil {
97 + if err := api.core().Request("id").Exec(ctx, &id); err != nil {
98 return nil, err
99 }
100
@@ -106,7 +106,7 @@ func (api *KeyAPI) Self(ctx context.Context) (iface.Key, error) {
106
107 func (api *KeyAPI) Remove(ctx context.Context, name string) (iface.Key, error) {
108 var out struct{ Keys []keyOutput }
109 - if err := api.core().request("key/rm", name).Exec(ctx, &out); err != nil {
109 + if err := api.core().Request("key/rm", name).Exec(ctx, &out); err != nil {
110 return nil, err
111 }
112 if len(out.Keys) != 1 {
client/httpapi/name.go
+3 -3
@@ -34,7 +34,7 @@ func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.Na
34 return nil, err
35 }
36
37 - req := api.core().request("name/publish", p.String()).
37 + req := api.core().Request("name/publish", p.String()).
38 Option("key", options.Key).
39 Option("allow-offline", options.AllowOffline).
40 Option("lifetime", options.ValidTime).
@@ -63,7 +63,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
63 return nil, fmt.Errorf("Name.Resolve: depth other than 1 or %d not supported", nsopts.DefaultDepthLimit)
64 }
65
66 - req := api.core().request("name/resolve", name).
66 + req := api.core().Request("name/resolve", name).
67 Option("nocache", !options.Cache).
68 Option("recursive", ropts.Depth != 1).
69 Option("dht-record-count", ropts.DhtRecordCount).
@@ -120,7 +120,7 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam
120 return nil, fmt.Errorf("Name.Resolve: depth other than 1 or %d not supported", nsopts.DefaultDepthLimit)
121 }
122
123 - req := api.core().request("name/resolve", name).
123 + req := api.core().Request("name/resolve", name).
124 Option("nocache", !options.Cache).
125 Option("recursive", ropts.Depth != 1).
126 Option("dht-record-count", ropts.DhtRecordCount).
client/httpapi/object.go
+9 -9
@@ -48,7 +48,7 @@ func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.Objec
48 }
49
50 var out objectOut
51 - err = api.core().request("object/put").
51 + err = api.core().Request("object/put").
52 Option("inputenc", options.InputEnc).
53 Option("datafieldenc", options.DataType).
54 Option("pin", options.Pin).
@@ -80,7 +80,7 @@ func (api *ObjectAPI) Get(ctx context.Context, p iface.Path) (ipld.Node, error)
80 }
81
82 func (api *ObjectAPI) Data(ctx context.Context, p iface.Path) (io.Reader, error) {
83 - resp, err := api.core().request("object/data", p.String()).Send(ctx)
83 + resp, err := api.core().Request("object/data", p.String()).Send(ctx)
84 if err != nil {
85 return nil, err
86 }
@@ -106,7 +106,7 @@ func (api *ObjectAPI) Links(ctx context.Context, p iface.Path) ([]*ipld.Link, er
106 Size uint64
107 }
108 }
109 - if err := api.core().request("object/links", p.String()).Exec(ctx, &out); err != nil {
109 + if err := api.core().Request("object/links", p.String()).Exec(ctx, &out); err != nil {
110 return nil, err
111 }
112 res := make([]*ipld.Link, len(out.Links))
@@ -135,7 +135,7 @@ func (api *ObjectAPI) Stat(ctx context.Context, p iface.Path) (*iface.ObjectStat
135 DataSize int
136 CumulativeSize int
137 }
138 - if err := api.core().request("object/stat", p.String()).Exec(ctx, &out); err != nil {
138 + if err := api.core().Request("object/stat", p.String()).Exec(ctx, &out); err != nil {
139 return nil, err
140 }
141
@@ -161,7 +161,7 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string,
161 }
162
163 var out objectOut
164 - err = api.core().request("object/patch/add-link", base.String(), name, child.String()).
164 + err = api.core().Request("object/patch/add-link", base.String(), name, child.String()).
165 Option("create", options.Create).
166 Exec(ctx, &out)
167 if err != nil {
@@ -178,7 +178,7 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string,
178
179 func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string) (iface.ResolvedPath, error) {
180 var out objectOut
181 - err := api.core().request("object/patch/rm-link", base.String(), link).
181 + err := api.core().Request("object/patch/rm-link", base.String(), link).
182 Exec(ctx, &out)
183 if err != nil {
184 return nil, err
@@ -194,7 +194,7 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string)
194
195 func (api *ObjectAPI) AppendData(ctx context.Context, p iface.Path, r io.Reader) (iface.ResolvedPath, error) {
196 var out objectOut
197 - err := api.core().request("object/patch/append-data", p.String()).
197 + err := api.core().Request("object/patch/append-data", p.String()).
198 FileBody(r).
199 Exec(ctx, &out)
200 if err != nil {
@@ -211,7 +211,7 @@ func (api *ObjectAPI) AppendData(ctx context.Context, p iface.Path, r io.Reader)
211
212 func (api *ObjectAPI) SetData(ctx context.Context, p iface.Path, r io.Reader) (iface.ResolvedPath, error) {
213 var out objectOut
214 - err := api.core().request("object/patch/set-data", p.String()).
214 + err := api.core().Request("object/patch/set-data", p.String()).
215 FileBody(r).
216 Exec(ctx, &out)
217 if err != nil {
@@ -237,7 +237,7 @@ func (api *ObjectAPI) Diff(ctx context.Context, a iface.Path, b iface.Path) ([]i
237 var out struct {
238 Changes []change
239 }
240 - if err := api.core().request("object/diff", a.String(), b.String()).Exec(ctx, &out); err != nil {
240 + if err := api.core().Request("object/diff", a.String(), b.String()).Exec(ctx, &out); err != nil {
241 return nil, err
242 }
243 res := make([]iface.ObjectChange, len(out.Changes))
client/httpapi/path.go
+1 -1
@@ -24,7 +24,7 @@ func (api *HttpApi) ResolvePath(ctx context.Context, path iface.Path) (iface.Res
24 }
25 }
26
27 - if err := api.request("dag/resolve", path.String()).Exec(ctx, &out); err != nil {
27 + if err := api.Request("dag/resolve", path.String()).Exec(ctx, &out); err != nil {
28 return nil, err
29 }
30
client/httpapi/pin.go
+5 -5
@@ -39,7 +39,7 @@ func (api *PinAPI) Add(ctx context.Context, p iface.Path, opts ...caopts.PinAddO
39 return err
40 }
41
42 - return api.core().request("pin/add", p.String()).
42 + return api.core().Request("pin/add", p.String()).
43 Option("recursive", options.Recursive).Exec(ctx, nil)
44 }
45
@@ -50,7 +50,7 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]iface.
50 }
51
52 var out pinRefKeyList
53 - err = api.core().request("pin/ls").
53 + err = api.core().Request("pin/ls").
54 Option("type", options.Type).Exec(ctx, &out)
55 if err != nil {
56 return nil, err
@@ -74,7 +74,7 @@ func (api *PinAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.PinRmOpt
74 return err
75 }
76
77 - return api.core().request("pin/rm", p.String()).
77 + return api.core().Request("pin/rm", p.String()).
78 Option("recursive", options.Recursive).
79 Exec(ctx, nil)
80 }
@@ -85,7 +85,7 @@ func (api *PinAPI) Update(ctx context.Context, from iface.Path, to iface.Path, o
85 return err
86 }
87
88 - return api.core().request("pin/update").
88 + return api.core().Request("pin/update").
89 Option("unpin", options.Unpin).Exec(ctx, nil)
90 }
91
@@ -116,7 +116,7 @@ func (n *badNode) Err() error {
116 }
117
118 func (api *PinAPI) Verify(ctx context.Context) (<-chan iface.PinStatus, error) {
119 - resp, err := api.core().request("pin/verify").Option("verbose", true).Send(ctx)
119 + resp, err := api.core().Request("pin/verify").Option("verbose", true).Send(ctx)
120 if err != nil {
121 return nil, err
122 }
client/httpapi/pubsub.go
+4 -4
@@ -18,7 +18,7 @@ func (api *PubsubAPI) Ls(ctx context.Context) ([]string, error) {
18 Strings []string
19 }
20
21 - if err := api.core().request("pubsub/ls").Exec(ctx, &out); err != nil {
21 + if err := api.core().Request("pubsub/ls").Exec(ctx, &out); err != nil {
22 return nil, err
23 }
24
@@ -35,7 +35,7 @@ func (api *PubsubAPI) Peers(ctx context.Context, opts ...caopts.PubSubPeersOptio
35 Strings []string
36 }
37
38 - if err := api.core().request("pubsub/peers", options.Topic).Exec(ctx, &out); err != nil {
38 + if err := api.core().Request("pubsub/peers", options.Topic).Exec(ctx, &out); err != nil {
39 return nil, err
40 }
41
@@ -51,7 +51,7 @@ func (api *PubsubAPI) Peers(ctx context.Context, opts ...caopts.PubSubPeersOptio
51 }
52
53 func (api *PubsubAPI) Publish(ctx context.Context, topic string, message []byte) error {
54 - return api.core().request("pubsub/pub", topic).
54 + return api.core().Request("pubsub/pub", topic).
55 FileBody(bytes.NewReader(message)).
56 Exec(ctx, nil)
57 }
@@ -112,7 +112,7 @@ func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopt
112 return nil, err
113 }
114
115 - resp, err := api.core().request("pubsub/sub", topic).
115 + resp, err := api.core().Request("pubsub/sub", topic).
116 Option("discover", options.Discover).Send(ctx)
117
118 if err != nil {
client/httpapi/swarm.go
+6 -6
@@ -25,11 +25,11 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi peerstore.PeerInfo) error {
25 saddrs[i] = addr.Encapsulate(pidma).String()
26 }
27
28 - return api.core().request("swarm/connect", saddrs...).Exec(ctx, nil)
28 + return api.core().Request("swarm/connect", saddrs...).Exec(ctx, nil)
29 }
30
31 func (api *SwarmAPI) Disconnect(ctx context.Context, addr multiaddr.Multiaddr) error {
32 - return api.core().request("swarm/disconnect", addr.String()).Exec(ctx, nil)
32 + return api.core().Request("swarm/disconnect", addr.String()).Exec(ctx, nil)
33 }
34
35 type connInfo struct {
@@ -75,7 +75,7 @@ func (api *SwarmAPI) Peers(ctx context.Context) ([]iface.ConnectionInfo, error)
75 }
76 }
77
78 - err := api.core().request("swarm/peers").
78 + err := api.core().Request("swarm/peers").
79 Option("streams", true).
80 Option("latency", true).
81 Exec(ctx, &resp)
@@ -116,7 +116,7 @@ func (api *SwarmAPI) KnownAddrs(ctx context.Context) (map[peer.ID][]multiaddr.Mu
116 var out struct {
117 Addrs map[string][]string
118 }
119 - if err := api.core().request("swarm/addrs").Exec(ctx, &out); err != nil {
119 + if err := api.core().Request("swarm/addrs").Exec(ctx, &out); err != nil {
120 return nil, err
121 }
122 res := map[peer.ID][]multiaddr.Multiaddr{}
@@ -147,7 +147,7 @@ func (api *SwarmAPI) LocalAddrs(ctx context.Context) ([]multiaddr.Multiaddr, err
147 Strings []string
148 }
149
150 - if err := api.core().request("swarm/addrs/local").Exec(ctx, &out); err != nil {
150 + if err := api.core().Request("swarm/addrs/local").Exec(ctx, &out); err != nil {
151 return nil, err
152 }
153
@@ -167,7 +167,7 @@ func (api *SwarmAPI) ListenAddrs(ctx context.Context) ([]multiaddr.Multiaddr, er
167 Strings []string
168 }
169
170 - if err := api.core().request("swarm/addrs/listen").Exec(ctx, &out); err != nil {
170 + if err := api.core().Request("swarm/addrs/listen").Exec(ctx, &out); err != nil {
171 return nil, err
172 }
173
client/httpapi/unixfs.go
+2 -2
@@ -36,7 +36,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.Unix
36 return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
37 }
38
39 - req := api.core().request("add").
39 + req := api.core().Request("add").
40 Option("hash", mht).
41 Option("chunker", options.Chunker).
42 Option("cid-version", options.CidVersion).
@@ -139,7 +139,7 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.Unixf
139 return nil, err
140 }
141
142 - resp, err := api.core().request("ls", p.String()).
142 + resp, err := api.core().Request("ls", p.String()).
143 Option("resolve-type", options.ResolveChildren).
144 Option("size", options.ResolveChildren).
145 Option("stream", true).