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
go-dms3
Commits
bbca4452
Commit
bbca4452
authored
10 years ago
by
Matt Bell
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/commands2: Added 'resolve' command
parent
109af013
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
core/commands2/resolve.go
core/commands2/resolve.go
+74
-0
core/commands2/root.go
core/commands2/root.go
+1
-0
No files found.
core/commands2/resolve.go
0 → 100644
View file @
bbca4452
package
commands
import
(
"errors"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
)
type
ResolveOutput
struct
{
Entries
[]
IpnsEntry
}
var
resolveCmd
=
&
cmds
.
Command
{
Arguments
:
[]
cmds
.
Argument
{
cmds
.
Argument
{
"name"
,
cmds
.
ArgString
,
false
,
true
},
},
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
name
:=
""
args
:=
req
.
Arguments
()
n
:=
req
.
Context
()
.
Node
var
output
[]
IpnsEntry
if
len
(
args
)
==
0
{
if
n
.
Identity
==
nil
{
res
.
SetError
(
errors
.
New
(
"Identity not loaded!"
),
cmds
.
ErrNormal
)
return
}
name
=
n
.
Identity
.
ID
()
.
String
()
entry
,
err
:=
resolve
(
name
,
n
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
output
=
[]
IpnsEntry
{
entry
}
}
else
{
output
=
make
([]
IpnsEntry
,
len
(
args
))
for
i
,
arg
:=
range
args
{
var
ok
bool
name
,
ok
=
arg
.
(
string
)
if
!
ok
{
res
.
SetError
(
errors
.
New
(
"cast error"
),
cmds
.
ErrNormal
)
return
}
entry
,
err
:=
resolve
(
name
,
n
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
output
[
i
]
=
entry
}
}
res
.
SetOutput
(
&
ResolveOutput
{
output
})
},
Type
:
&
ResolveOutput
{},
}
func
resolve
(
name
string
,
n
*
core
.
IpfsNode
)
(
IpnsEntry
,
error
)
{
resolved
,
err
:=
n
.
Namesys
.
Resolve
(
name
)
if
err
!=
nil
{
return
IpnsEntry
{},
err
}
return
IpnsEntry
{
Name
:
name
,
Value
:
resolved
,
},
nil
}
This diff is collapsed.
Click to expand it.
core/commands2/root.go
View file @
bbca4452
...
...
@@ -65,6 +65,7 @@ var rootSubcommands = map[string]*cmds.Command{
"diag"
:
diagCmd
,
"pin"
:
pinCmd
,
"unpin"
:
unpinCmd
,
"resolve"
:
resolveCmd
,
// test subcommands
// TODO: remove these when we don't need them anymore
...
...
This diff is collapsed.
Click to expand it.
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