Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

feat: LsBatchSync to fetch single batch of results #4

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -257,7 +281,7 @@ func (pinAddOpts) WithName(name string) AddOption {
}
}

func (pinLsOpts) WithOrigins(origins ...multiaddr.Multiaddr) AddOption {
func (pinAddOpts) WithOrigins(origins ...multiaddr.Multiaddr) AddOption {
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved
return func(options *addSettings) error {
for _, o := range origins {
options.origins = append(options.origins, o.String())
Expand Down Expand Up @@ -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 {
Expand Down