@cryptotaxi247 / kubo / commits / 60039f27b

object coreapi: Address review

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jul 25, 2018 at 22:49 UTC 60039f27bac457aa9f71cc002661eba1b55a65d6
5 files changed +17 -18
commands/request.go
-6
@@ -68,12 +68,6 @@ func (c *Context) GetApi() (coreiface.CoreAPI, error) {
68 return c.api, nil
69 }
70
71 -// NodeWithoutConstructing returns the underlying node variable
72 -// so that clients may close it.
73 -func (c *Context) NodeWithoutConstructing() *core.IpfsNode {
74 - return c.node
75 -}
76 -
71 // Context returns the node's context.
72 func (c *Context) Context() context.Context {
73 n, err := c.GetNode()
core/commands/env.go
+4 -2
@@ -7,6 +7,8 @@ import (
7 "github.com/ipfs/go-ipfs/core"
8 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
9 "github.com/ipfs/go-ipfs/repo/config"
10 +
11 + cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
12 )
13
14 // GetNode extracts the node from the environment.
@@ -20,7 +22,7 @@ func GetNode(env interface{}) (*core.IpfsNode, error) {
22 }
23
24 // GetApi extracts CoreAPI instance from the environment.
23 -func GetApi(env interface{}) (coreiface.CoreAPI, error) {
25 +func GetApi(env cmds.Environment) (coreiface.CoreAPI, error) {
26 ctx, ok := env.(*commands.Context)
27 if !ok {
28 return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
@@ -30,7 +32,7 @@ func GetApi(env interface{}) (coreiface.CoreAPI, error) {
32 }
33
34 // GetConfig extracts the config from the environment.
33 -func GetConfig(env interface{}) (*config.Config, error) {
35 +func GetConfig(env cmds.Environment) (*config.Config, error) {
36 ctx, ok := env.(*commands.Context)
37 if !ok {
38 return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
core/commands/object/patch.go
+1 -1
@@ -254,7 +254,7 @@ to a file containing 'bar', and returns the hash of the new object.
254 // TODO: fix import loop with core/commands so we don't need that
255 // COPIED FROM ONE LEVEL UP
256 // GetApi extracts CoreAPI instance from the environment.
257 -func GetApi(env interface{}) (coreiface.CoreAPI, error) {
257 +func GetApi(env cmds.Environment) (coreiface.CoreAPI, error) {
258 ctx, ok := env.(*oldcmds.Context)
259 if !ok {
260 return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
core/coreapi/interface/object.go
+8 -6
@@ -31,25 +31,27 @@ type ObjectStat struct {
31 CumulativeSize int
32 }
33
34 +// ChangeType denotes type of change in ObjectChange
35 +type ChangeType int
36 +
37 const (
35 - // DiffAdd is a Type of ObjectChange where a link was added to the graph
36 - DiffAdd = iota
38 + // DiffAdd is set when a link was added to the graph
39 + DiffAdd ChangeType = iota
40
38 - // DiffRemove is a Type of ObjectChange where a link was removed from the graph
41 + // DiffRemove is set when a link was removed from the graph
42 DiffRemove
43
41 - // DiffMod is a Type of ObjectChange where a link was changed in the graph
44 + // DiffMod is set when a link was changed in the graph
45 DiffMod
46 )
47
48 // ObjectChange represents a change ia a graph
46 -// TODO: do we want this to be an interface?
49 type ObjectChange struct {
50 // Type of the change, either:
51 // * DiffAdd - Added a link
52 // * DiffRemove - Removed a link
53 // * DiffMod - Modified a link
52 - Type int
54 + Type ChangeType
55
56 // Path to the changed link
57 Path string
dagutils/diff.go
+4 -3
@@ -5,9 +5,10 @@ import (
5 "fmt"
6 "path"
7
8 - dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
8 + coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
9
10 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
10 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
11 + "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
12 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
13 )
14
@@ -21,7 +22,7 @@ const (
22 // Change represents a change to a DAG and contains a reference to the old and
23 // new CIDs.
24 type Change struct {
24 - Type int
25 + Type coreiface.ChangeType
26 Path string
27 Before *cid.Cid
28 After *cid.Cid