Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-pinning-service-http-client
Commits
9087f9a0
Unverified
Commit
9087f9a0
authored
Nov 30, 2020
by
Adin Schmahmann
Committed by
GitHub
Nov 30, 2020
Browse files
Options
Browse Files
Download
Plain Diff
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
5 deletions
+29
-5
client.go
client.go
+29
-5
No files found.
client.go
View file @
9087f9a0
...
...
@@ -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
(
pin
Ls
Opts
)
WithOrigins
(
origins
...
multiaddr
.
Multiaddr
)
AddOption
{
func
(
pin
Add
Opts
)
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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment