Unverified Commit 9087f9a0 authored by Adin Schmahmann's avatar Adin Schmahmann Committed by GitHub

Merge pull request #6 from ipfs/feat/ls-with-limit

feat: LsBatchSync to fetch single batch of results
parents 390a4c0e 7ffc18b3
Pipeline #225 failed with stages
in 0 seconds
......@@ -195,6 +195,30 @@ func (c *Client) LsSync(ctx context.Context, opts ...LsOption) ([]PinStatusGette
return res, <-errCh
}
// Manual version of Ls that returns a single batch of results and int with total count
func (c *Client) LsBatchSync(ctx context.Context, opts ...LsOption) ([]PinStatusGetter, int, error) {
var res []PinStatusGetter
settings := new(lsSettings)
for _, o := range opts {
if err := o(settings); err != nil {
return nil, 0, err
}
}
pinRes, err := c.lsInternal(ctx, settings)
if err != nil {
return nil, 0, err
}
results := pinRes.GetResults()
for _, r := range results {
res = append(res, &pinStatusObject{r})
}
return res, int(pinRes.Count), nil
}
func (c *Client) lsInternal(ctx context.Context, settings *lsSettings) (pinResults, error) {
getter := c.client.PinsApi.PinsGet(ctx)
if len(settings.cids) > 0 {
......@@ -257,7 +281,7 @@ func (pinAddOpts) WithName(name string) AddOption {
}
}
func (pinLsOpts) WithOrigins(origins ...multiaddr.Multiaddr) AddOption {
func (pinAddOpts) WithOrigins(origins ...multiaddr.Multiaddr) AddOption {
return func(options *addSettings) error {
for _, o := range origins {
options.origins = append(options.origins, o.String())
......@@ -326,7 +350,7 @@ func (c *Client) DeleteByID(ctx context.Context, pinID string) error {
return nil
}
func (c *Client) Modify(ctx context.Context, pinID string, cid cid.Cid, opts ...AddOption) (PinStatusGetter, error) {
func (c *Client) Replace(ctx context.Context, pinID string, cid cid.Cid, opts ...AddOption) (PinStatusGetter, error) {
settings := new(addSettings)
for _, o := range opts {
if err := o(settings); err != nil {
......@@ -371,13 +395,13 @@ func httperr(resp *http.Response, e error) error {
if ok {
ferr, ok := oerr.Model().(openapi.Failure)
if ok {
return errors.Wrapf(e,"statusCode: %d, reason : %q, details : %q", resp.StatusCode, ferr.Error.GetReason(), ferr.Error.GetDetails())
return errors.Wrapf(e, "reason: %q, details: %q", ferr.Error.GetReason(), ferr.Error.GetDetails())
}
}
if resp == nil {
return errors.Wrapf(e,"empty response from remote pinning service")
return errors.Wrapf(e, "empty response from remote pinning service")
}
return errors.Wrapf(e, "remote pinning service error. statusCode: %d", resp.StatusCode)
return errors.Wrapf(e, "remote pinning service returned http error %d", resp.StatusCode)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment