@cryptotaxi247 / kubo / commits / 63e861e54

coreapi: expand public path api

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@ad6db2fc4cff3178bb50aacbe30559078661907b This commit was moved from ipfs/boxo@3b1cf7aed3af88561e5b851f79d4b480c59d1ce5

Łukasz Magiera committed Feb 2, 2018 at 16:00 UTC 63e861e549469348c5b075da5920df32c12689b9
2 files changed +43
core/coreiface/coreapi.go
+13
@@ -5,6 +5,9 @@ package iface
5 import (
6 "context"
7
8 + options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9 +
10 + cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
11 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
12 )
13
@@ -37,4 +40,14 @@ type CoreAPI interface {
40 // ResolveNode resolves the path (if not resolved already) using Unixfs
41 // resolver, gets and returns the resolved Node
42 ResolveNode(context.Context, Path) (ipld.Node, error)
43 +
44 + // ParsePath parses string path to a Path
45 + ParsePath(context.Context, string, ...options.ParsePathOption) (Path, error)
46 +
47 + // WithResolve is an option for ParsePath which when set to true tells
48 + // ParsePath to also resolve the path
49 + WithResolve(bool) options.ParsePathOption
50 +
51 + // ParseCid creates new path from the provided CID
52 + ParseCid(*cid.Cid) Path
53 }
core/coreiface/options/path.go new
+30
@@ -0,0 +1,30 @@
1 +package options
2 +
3 +type ParsePathSettings struct {
4 + Resolve bool
5 +}
6 +
7 +type ParsePathOption func(*ParsePathSettings) error
8 +
9 +func ParsePathOptions(opts ...ParsePathOption) (*ParsePathSettings, error) {
10 + options := &ParsePathSettings{
11 + Resolve: false,
12 + }
13 +
14 + for _, opt := range opts {
15 + err := opt(options)
16 + if err != nil {
17 + return nil, err
18 + }
19 + }
20 + return options, nil
21 +}
22 +
23 +type ApiOptions struct{}
24 +
25 +func (api *ApiOptions) WithResolve(r bool) ParsePathOption {
26 + return func(settings *ParsePathSettings) error {
27 + settings.Resolve = r
28 + return nil
29 + }
30 +}