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
57b3ffa5
Commit
57b3ffa5
authored
Jan 10, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: new core constructor + config options (Standard, Online, Offline)
parent
007ffd40
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
4 deletions
+35
-4
cmd/ipfs/init.go
cmd/ipfs/init.go
+1
-1
cmd/ipfs/main.go
cmd/ipfs/main.go
+1
-1
core/core.go
core/core.go
+31
-0
core/core_test.go
core/core_test.go
+2
-2
No files found.
cmd/ipfs/init.go
View file @
57b3ffa5
...
...
@@ -121,7 +121,7 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
func
addTheWelcomeFile
(
conf
*
config
.
Config
)
error
{
// TODO extract this file creation operation into a function
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
nd
,
err
:=
core
.
NewI
pfs
Node
(
ctx
,
co
nf
,
false
)
nd
,
err
:=
core
.
NewI
PFS
Node
(
ctx
,
co
re
.
Offline
(
conf
)
)
if
err
!=
nil
{
return
err
}
...
...
cmd/ipfs/main.go
View file @
57b3ffa5
...
...
@@ -188,7 +188,7 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf
// ok everything is good. set it on the invocation (for ownership)
// and return it.
i
.
node
,
err
=
core
.
NewI
pfs
Node
(
ctx
,
cfg
,
cmdctx
.
Online
)
i
.
node
,
err
=
core
.
NewI
PFS
Node
(
ctx
,
core
.
Standard
(
cfg
,
cmdctx
.
Online
)
)
return
i
.
node
,
err
}
}
...
...
core/core.go
View file @
57b3ffa5
package
core
import
(
"errors"
"fmt"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -75,7 +76,37 @@ type Mounts struct {
Ipns
mount
.
Mount
}
var
errTODO
=
errors
.
New
(
"TODO"
)
type
Configuration
*
IpfsNode
// define a different type
type
ConfigOption
func
(
ctx
context
.
Context
)
(
Configuration
,
error
)
func
NewIPFSNode
(
ctx
context
.
Context
,
option
ConfigOption
)
(
*
IpfsNode
,
error
)
{
config
,
err
:=
option
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
return
config
,
nil
}
func
Offline
(
cfg
*
config
.
Config
)
ConfigOption
{
return
Standard
(
cfg
,
false
)
}
func
Online
(
cfg
*
config
.
Config
)
ConfigOption
{
return
Standard
(
cfg
,
true
)
}
// DEPRECATED: use Online, Offline functions
func
Standard
(
cfg
*
config
.
Config
,
online
bool
)
ConfigOption
{
return
func
(
ctx
context
.
Context
)
(
Configuration
,
error
)
{
return
NewIpfsNode
(
ctx
,
cfg
,
online
)
}
}
// NewIpfsNode constructs a new IpfsNode based on the given config.
// DEPRECATED: use `NewIPFSNode`
func
NewIpfsNode
(
ctx
context
.
Context
,
cfg
*
config
.
Config
,
online
bool
)
(
n
*
IpfsNode
,
err
error
)
{
success
:=
false
// flip to true after all sub-system inits succeed
defer
func
()
{
...
...
core/core_test.go
View file @
57b3ffa5
...
...
@@ -45,14 +45,14 @@ func TestInitialization(t *testing.T) {
}
for
i
,
c
:=
range
good
{
n
,
err
:=
NewI
pfs
Node
(
ctx
,
c
,
false
)
n
,
err
:=
NewI
PFS
Node
(
ctx
,
Standard
(
c
,
false
)
)
if
n
==
nil
||
err
!=
nil
{
t
.
Error
(
"Should have constructed."
,
i
,
err
)
}
}
for
i
,
c
:=
range
bad
{
n
,
err
:=
NewI
pfs
Node
(
ctx
,
c
,
false
)
n
,
err
:=
NewI
PFS
Node
(
ctx
,
Standard
(
c
,
false
)
)
if
n
!=
nil
||
err
==
nil
{
t
.
Error
(
"Should have failed to construct."
,
i
)
}
...
...
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