Commit b3293937 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi: pin draft

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent bf7867a2
......@@ -58,6 +58,15 @@ type BlockStat interface {
Path() Path
}
// Pin holds information about pinned resource
type Pin interface {
// Path to the pinned object
Path() Path
// Type of the pin
Type() string
}
// CoreAPI defines an unified interface to IPFS for Go programs.
type CoreAPI interface {
// Unixfs returns an implementation of Unixfs API.
......@@ -322,5 +331,40 @@ type ObjectStat struct {
CumulativeSize int
}
// PinAPI specifies the interface to pining
type PinAPI interface {
// Add creates new pin, be default recursive - pinning the whole referenced
// tree
Add(context.Context, Path, ...options.PinAddOption) error
// WithRecursive is an option for Add which specifies whether to pin an entire
// object tree or just one object. Default: true
WithRecursive(bool) options.PinAddOption
// Ls returns list of pinned objects on this node
Ls(context.Context) ([]Pin, error)
// WithType is an option for Ls which allows to specify which pin types should
// be returned
//
// Supported values:
// * "direct" - directly pinned objects
// * "recursive" - roots of recursive pins
// * "indirect" - indirectly pinned objects (referenced by recursively pinned
// objects)
// * "all" - all pinned objects (default)
WithType(string) options.PinLsOption
// Rm removes pin for object specified by the path
Rm(context.Context, Path) error
// Update changes one pin to another, skipping checks for matching paths in
// the old tree
Update(ctx context.Context, from Path, to Path) error
// Verify verifies the integrity of pinned objects
Verify(context.Context) error
}
var ErrIsDir = errors.New("object is a directory")
var ErrOffline = errors.New("can't resolve, ipfs node is offline")
package options
type PinAddSettings struct {
Recursive bool
}
type PinLsSettings struct {
Type string
}
type PinAddOption func(*PinAddSettings) error
type PinLsOption func(settings *PinLsSettings) error
func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
options := &PinAddSettings{
Recursive: true,
}
for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}
return options, nil
}
func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
options := &PinLsSettings{
Type: "all",
}
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 {
return func(settings *PinAddSettings) error {
settings.Recursive = recucsive
return nil
}
}
func (api *PinOptions) WithType(t string) PinLsOption {
return func(settings *PinLsSettings) error {
settings.Type = t
return nil
}
}
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