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
interface-go-dms3-core
Commits
4597fde8
Commit
4597fde8
authored
Jan 10, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: implement pin api
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
b3293937
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
3 deletions
+49
-3
interface.go
interface.go
+22
-3
options/pin.go
options/pin.go
+27
-0
No files found.
interface.go
View file @
4597fde8
...
...
@@ -67,6 +67,24 @@ type Pin interface {
Type
()
string
}
// PinStatus holds information about pin health
type
PinStatus
interface
{
// Ok indicates whether the pin has been verified to be correct
Ok
()
bool
// BadNodes returns any bad (usually missing) nodes from the pin
BadNodes
()
[]
BadPinNode
}
// BadPinNode is a node that has been marked as bad by Pin.Verify
type
BadPinNode
interface
{
// Path is the path of the node
Path
()
Path
// Err is the reason why the node has been marked as bad
Err
()
error
}
// CoreAPI defines an unified interface to IPFS for Go programs.
type
CoreAPI
interface
{
// Unixfs returns an implementation of Unixfs API.
...
...
@@ -83,6 +101,7 @@ type CoreAPI interface {
// Key returns an implementation of Key API.
Key
()
KeyAPI
Pin
()
PinAPI
// ObjectAPI returns an implementation of Object API
Object
()
ObjectAPI
...
...
@@ -342,7 +361,7 @@ type PinAPI interface {
WithRecursive
(
bool
)
options
.
PinAddOption
// Ls returns list of pinned objects on this node
Ls
(
context
.
Context
)
([]
Pin
,
error
)
Ls
(
context
.
Context
,
...
options
.
PinLsOption
)
([]
Pin
,
error
)
// WithType is an option for Ls which allows to specify which pin types should
// be returned
...
...
@@ -360,10 +379,10 @@ type PinAPI interface {
// Update changes one pin to another, skipping checks for matching paths in
// the old tree
Update
(
ctx
context
.
Context
,
from
Path
,
to
Path
)
error
Update
(
ctx
context
.
Context
,
from
Path
,
to
Path
,
opts
...
options
.
PinUpdateOption
)
error
// Verify verifies the integrity of pinned objects
Verify
(
context
.
Context
)
error
Verify
(
context
.
Context
)
(
<-
chan
PinStatus
,
error
)
}
var
ErrIsDir
=
errors
.
New
(
"object is a directory"
)
...
...
options/pin.go
View file @
4597fde8
...
...
@@ -8,8 +8,13 @@ type PinLsSettings struct {
Type
string
}
type
PinUpdateSettings
struct
{
Unpin
bool
}
type
PinAddOption
func
(
*
PinAddSettings
)
error
type
PinLsOption
func
(
settings
*
PinLsSettings
)
error
type
PinUpdateOption
func
(
*
PinUpdateSettings
)
error
func
PinAddOptions
(
opts
...
PinAddOption
)
(
*
PinAddSettings
,
error
)
{
options
:=
&
PinAddSettings
{
...
...
@@ -41,6 +46,21 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
return
options
,
nil
}
func
PinUpdateOptions
(
opts
...
PinUpdateOption
)
(
*
PinUpdateSettings
,
error
)
{
options
:=
&
PinUpdateSettings
{
Unpin
:
true
,
}
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
options
,
nil
}
type
PinOptions
struct
{}
func
(
api
*
PinOptions
)
WithRecursive
(
recucsive
bool
)
PinAddOption
{
...
...
@@ -56,3 +76,10 @@ func (api *PinOptions) WithType(t string) PinLsOption {
return
nil
}
}
func
(
api
*
PinOptions
)
WithUnpin
(
unpin
bool
)
PinUpdateOption
{
return
func
(
settings
*
PinUpdateSettings
)
error
{
settings
.
Unpin
=
unpin
return
nil
}
}
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