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

coreapi: expand public path api

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 2c9291a2
...@@ -5,6 +5,9 @@ package iface ...@@ -5,6 +5,9 @@ package iface
import ( import (
"context" "context"
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format" ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
) )
...@@ -37,4 +40,14 @@ type CoreAPI interface { ...@@ -37,4 +40,14 @@ type CoreAPI interface {
// ResolveNode resolves the path (if not resolved already) using Unixfs // ResolveNode resolves the path (if not resolved already) using Unixfs
// resolver, gets and returns the resolved Node // resolver, gets and returns the resolved Node
ResolveNode(context.Context, Path) (ipld.Node, error) ResolveNode(context.Context, Path) (ipld.Node, error)
// ParsePath parses string path to a Path
ParsePath(context.Context, string, ...options.ParsePathOption) (Path, error)
// WithResolve is an option for ParsePath which when set to true tells
// ParsePath to also resolve the path
WithResolve(bool) options.ParsePathOption
// ParseCid creates new path from the provided CID
ParseCid(*cid.Cid) Path
} }
package options
type ParsePathSettings struct {
Resolve bool
}
type ParsePathOption func(*ParsePathSettings) error
func ParsePathOptions(opts ...ParsePathOption) (*ParsePathSettings, error) {
options := &ParsePathSettings{
Resolve: false,
}
for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}
return options, nil
}
type ApiOptions struct{}
func (api *ApiOptions) WithResolve(r bool) ParsePathOption {
return func(settings *ParsePathSettings) error {
settings.Resolve = r
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