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-unixfs
Commits
e86e7d87
Commit
e86e7d87
authored
Nov 04, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract publish func
parent
96fd88e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
15 deletions
+26
-15
core/commands2/publish.go
core/commands2/publish.go
+26
-15
No files found.
core/commands2/publish.go
View file @
e86e7d87
...
...
@@ -5,12 +5,15 @@ import (
"fmt"
cmds
"github.com/jbenet/go-ipfs/commands"
core
"github.com/jbenet/go-ipfs/core"
crypto
"github.com/jbenet/go-ipfs/crypto"
nsys
"github.com/jbenet/go-ipfs/namesys"
u
"github.com/jbenet/go-ipfs/util"
)
type
PublishOutput
struct
{
Name
,
Value
string
Name
string
Value
string
}
var
publishCmd
=
&
cmds
.
Command
{
...
...
@@ -40,26 +43,16 @@ var publishCmd = &cmds.Command{
default
:
res
.
SetError
(
fmt
.
Errorf
(
"Publish expects 1 or 2 args; got %d."
,
len
(
args
)),
cmds
.
ErrClient
)
}
// later, n.Keychain.Get(name).PrivKey
k
:=
n
.
Identity
.
PrivKey
()
pub
:=
nsys
.
NewRoutingPublisher
(
n
.
Routing
)
err
:=
pub
.
Publish
(
k
,
ref
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
// TODO n.Keychain.Get(name).PrivKey
k
:=
n
.
Identity
.
PrivKey
()
publishOutput
,
err
:=
publish
(
n
,
k
,
ref
)
hash
,
err
:=
k
.
GetPublic
()
.
Hash
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
&
PublishOutput
{
Name
:
u
.
Key
(
hash
)
.
String
(),
Value
:
ref
,
})
res
.
SetOutput
(
publishOutput
)
},
Marshallers
:
map
[
cmds
.
EncodingType
]
cmds
.
Marshaller
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
...
...
@@ -70,3 +63,21 @@ var publishCmd = &cmds.Command{
},
Type
:
&
PublishOutput
{},
}
func
publish
(
n
*
core
.
IpfsNode
,
k
crypto
.
PrivKey
,
ref
string
)
(
*
PublishOutput
,
error
)
{
pub
:=
nsys
.
NewRoutingPublisher
(
n
.
Routing
)
err
:=
pub
.
Publish
(
k
,
ref
)
if
err
!=
nil
{
return
nil
,
err
}
hash
,
err
:=
k
.
GetPublic
()
.
Hash
()
if
err
!=
nil
{
return
nil
,
err
}
return
&
PublishOutput
{
Name
:
u
.
Key
(
hash
)
.
String
(),
Value
:
ref
,
},
nil
}
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