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
0a0e69cc
Commit
0a0e69cc
authored
Jun 12, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: move path utils to interface
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
1806f0f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
10 deletions
+87
-10
coreapi.go
coreapi.go
+0
-10
path.go
path.go
+87
-0
No files found.
coreapi.go
View file @
0a0e69cc
...
...
@@ -6,7 +6,6 @@ import (
"context"
ipld
"gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
cid
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
)
// CoreAPI defines an unified interface to IPFS for Go programs
...
...
@@ -38,13 +37,4 @@ type CoreAPI interface {
// ResolveNode resolves the path (if not resolved already) using Unixfs
// resolver, gets and returns the resolved Node
ResolveNode
(
context
.
Context
,
Path
)
(
ipld
.
Node
,
error
)
// ParsePath parses string path to a Path
ParsePath
(
string
)
(
Path
,
error
)
// IpfsPath creates new /ipfs path from the provided CID
IpfsPath
(
*
cid
.
Cid
)
ResolvedPath
// IpldPath creates new /ipld path from the provided CID
IpldPath
(
*
cid
.
Cid
)
ResolvedPath
}
path.go
View file @
0a0e69cc
package
iface
import
(
ipfspath
"github.com/ipfs/go-ipfs/path"
cid
"gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
)
//TODO: merge with ipfspath so we don't depend on it
// Path is a generic wrapper for paths used in the API. A path can be resolved
// to a CID using one of Resolve functions in the API.
//
...
...
@@ -87,3 +91,86 @@ type ResolvedPath interface {
Path
}
// path implements coreiface.Path
type
path
struct
{
path
ipfspath
.
Path
}
// resolvedPath implements coreiface.resolvedPath
type
resolvedPath
struct
{
path
cid
*
cid
.
Cid
root
*
cid
.
Cid
remainder
string
}
// IpfsPath creates new /ipfs path from the provided CID
func
IpfsPath
(
c
*
cid
.
Cid
)
ResolvedPath
{
return
&
resolvedPath
{
path
:
path
{
ipfspath
.
Path
(
"/ipfs/"
+
c
.
String
())},
cid
:
c
,
root
:
c
,
remainder
:
""
,
}
}
// IpldPath creates new /ipld path from the provided CID
func
IpldPath
(
c
*
cid
.
Cid
)
ResolvedPath
{
return
&
resolvedPath
{
path
:
path
{
ipfspath
.
Path
(
"/ipld/"
+
c
.
String
())},
cid
:
c
,
root
:
c
,
remainder
:
""
,
}
}
// ParsePath parses string path to a Path
func
ParsePath
(
p
string
)
(
Path
,
error
)
{
pp
,
err
:=
ipfspath
.
ParsePath
(
p
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
path
{
path
:
pp
},
nil
}
// NewResolvedPath creates new ResolvedPath. This function performs no checks
// and is intended to be used by resolver implementations. Incorrect inputs may
// cause panics. Handle with care.
func
NewResolvedPath
(
ipath
ipfspath
.
Path
,
c
*
cid
.
Cid
,
root
*
cid
.
Cid
,
remainder
string
)
ResolvedPath
{
return
&
resolvedPath
{
path
:
path
{
ipath
},
cid
:
c
,
root
:
root
,
remainder
:
remainder
,
}
}
func
(
p
*
path
)
String
()
string
{
return
p
.
path
.
String
()
}
func
(
p
*
path
)
Namespace
()
string
{
if
len
(
p
.
path
.
Segments
())
<
1
{
panic
(
"path without namespace"
)
//this shouldn't happen under any scenario
}
return
p
.
path
.
Segments
()[
0
]
}
func
(
p
*
path
)
Mutable
()
bool
{
//TODO: MFS: check for /local
return
p
.
Namespace
()
==
"ipns"
}
func
(
p
*
resolvedPath
)
Cid
()
*
cid
.
Cid
{
return
p
.
cid
}
func
(
p
*
resolvedPath
)
Root
()
*
cid
.
Cid
{
return
p
.
root
}
func
(
p
*
resolvedPath
)
Remainder
()
string
{
return
p
.
remainder
}
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