go fmt
Juan Batiz-Benet committed
Jul 5, 2014 at 13:21 UTC
2d7f2473a51c5614eddcd446867022cf9ee4bfca
3 files changed
+82
-80
core/core.go
+40
-40
@@ -1,62 +1,62 @@
1
package core
2
3
import (
4
- config "github.com/jbenet/go-ipfs/config"
5
- ds "github.com/jbenet/datastore.go"
6
- "fmt"
7
- peer "github.com/jbenet/go-ipfs/peer"
4
+ "fmt"
5
+ ds "github.com/jbenet/datastore.go"
6
+ config "github.com/jbenet/go-ipfs/config"
7
+ peer "github.com/jbenet/go-ipfs/peer"
8
)
9
10
// IPFS Core module. It represents an IPFS instance.
11
12
type IpfsNode struct {
13
14
- // the node's configuration
15
- Config *config.Config
14
+ // the node's configuration
15
+ Config *config.Config
16
17
- // the local node's identity
18
- Identity *peer.Peer
17
+ // the local node's identity
18
+ Identity *peer.Peer
19
20
- // the book of other nodes (a map of Peer instances)
21
- PeerBook *peer.PeerBook
20
+ // the book of other nodes (a map of Peer instances)
21
+ PeerBook *peer.PeerBook
22
23
- // the local datastore
24
- Datastore ds.Datastore
23
+ // the local datastore
24
+ Datastore ds.Datastore
25
26
- // the network message stream
27
- // Network *netmux.Netux
26
+ // the network message stream
27
+ // Network *netmux.Netux
28
29
- // the routing system. recommend ipfs-dht
30
- // Routing *routing.Routing
29
+ // the routing system. recommend ipfs-dht
30
+ // Routing *routing.Routing
31
32
- // the block exchange + strategy (bitswap)
33
- // BitSwap *bitswap.BitSwap
32
+ // the block exchange + strategy (bitswap)
33
+ // BitSwap *bitswap.BitSwap
34
35
- // the block service, get/add blocks.
36
- // Blocks *blocks.BlockService
35
+ // the block service, get/add blocks.
36
+ // Blocks *blocks.BlockService
37
38
- // the path resolution system
39
- // Resolver *resolver.PathResolver
38
+ // the path resolution system
39
+ // Resolver *resolver.PathResolver
40
41
- // the name system, resolves paths to hashes
42
- // Namesys *namesys.Namesys
41
+ // the name system, resolves paths to hashes
42
+ // Namesys *namesys.Namesys
43
}
44
45
func NewIpfsNode(cfg *config.Config) (*IpfsNode, error) {
46
- if cfg == nil {
47
- return nil, fmt.Errorf("configuration required.")
48
- }
49
-
50
- d, err := makeDatastore(cfg.Datastore)
51
- if err != nil {
52
- return nil, err
53
- }
54
-
55
- n := &IpfsNode{
56
- Config: cfg,
57
- PeerBook: &peer.PeerBook{},
58
- Datastore: d,
59
- }
60
-
61
- return n, nil
46
+ if cfg == nil {
47
+ return nil, fmt.Errorf("configuration required.")
48
+ }
49
+
50
+ d, err := makeDatastore(cfg.Datastore)
51
+ if err != nil {
52
+ return nil, err
53
+ }
54
+
55
+ n := &IpfsNode{
56
+ Config: cfg,
57
+ PeerBook: &peer.PeerBook{},
58
+ Datastore: d,
59
+ }
60
+
61
+ return n, nil
62
}
core/core_test.go
+24
-24
@@ -1,35 +1,35 @@
1
package core
2
3
import (
4
- "testing"
5
- config "github.com/jbenet/go-ipfs/config"
4
+ config "github.com/jbenet/go-ipfs/config"
5
+ "testing"
6
)
7
8
func TestDatastores(t *testing.T) {
9
10
- good := []*config.Config {
11
- &config.Config{ Datastore: &config.Datastore{Type: "memory"} },
12
- &config.Config{ Datastore: &config.Datastore{Type: "leveldb", Path: ".testdb"} },
13
- }
10
+ good := []*config.Config{
11
+ &config.Config{Datastore: &config.Datastore{Type: "memory"}},
12
+ &config.Config{Datastore: &config.Datastore{Type: "leveldb", Path: ".testdb"}},
13
+ }
14
15
- bad := []*config.Config {
16
- &config.Config{ Datastore: &config.Datastore{} },
17
- &config.Config{ Datastore: &config.Datastore{Type: "badtype"} },
18
- &config.Config{ },
19
- nil,
20
- }
15
+ bad := []*config.Config{
16
+ &config.Config{Datastore: &config.Datastore{}},
17
+ &config.Config{Datastore: &config.Datastore{Type: "badtype"}},
18
+ &config.Config{},
19
+ nil,
20
+ }
21
22
- for i, c := range(good) {
23
- n, err := NewIpfsNode(c)
24
- if n == nil || err != nil {
25
- t.Error("Should have constructed.", i, err)
26
- }
27
- }
22
+ for i, c := range good {
23
+ n, err := NewIpfsNode(c)
24
+ if n == nil || err != nil {
25
+ t.Error("Should have constructed.", i, err)
26
+ }
27
+ }
28
29
- for i, c := range(bad) {
30
- n, err := NewIpfsNode(c)
31
- if n != nil || err == nil {
32
- t.Error("Should have failed to construct.", i)
33
- }
34
- }
29
+ for i, c := range bad {
30
+ n, err := NewIpfsNode(c)
31
+ if n != nil || err == nil {
32
+ t.Error("Should have failed to construct.", i)
33
+ }
34
+ }
35
}
core/datastore.go
+18
-16
@@ -1,29 +1,31 @@
1
package core
2
3
import (
4
- config "github.com/jbenet/go-ipfs/config"
5
- ds "github.com/jbenet/datastore.go"
6
- "fmt"
7
- lds "github.com/jbenet/datastore.go/leveldb"
4
+ "fmt"
5
+ ds "github.com/jbenet/datastore.go"
6
+ lds "github.com/jbenet/datastore.go/leveldb"
7
+ config "github.com/jbenet/go-ipfs/config"
8
)
9
10
func makeDatastore(cfg *config.Datastore) (ds.Datastore, error) {
11
- if cfg == nil || len(cfg.Type) == 0 {
12
- return nil, fmt.Errorf("config datastore.type required")
13
- }
11
+ if cfg == nil || len(cfg.Type) == 0 {
12
+ return nil, fmt.Errorf("config datastore.type required")
13
+ }
14
15
- switch cfg.Type {
16
- case "leveldb": return makeLevelDBDatastore(cfg)
17
- case "memory": return ds.NewMapDatastore(), nil
18
- }
15
+ switch cfg.Type {
16
+ case "leveldb":
17
+ return makeLevelDBDatastore(cfg)
18
+ case "memory":
19
+ return ds.NewMapDatastore(), nil
20
+ }
21
20
- return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
22
+ return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
23
}
24
25
func makeLevelDBDatastore(cfg *config.Datastore) (ds.Datastore, error) {
24
- if len(cfg.Path) == 0 {
25
- return nil, fmt.Errorf("config datastore.path required for leveldb")
26
- }
26
+ if len(cfg.Path) == 0 {
27
+ return nil, fmt.Errorf("config datastore.path required for leveldb")
28
+ }
29
28
- return lds.NewDatastore(cfg.Path, nil)
30
+ return lds.NewDatastore(cfg.Path, nil)
31
}