/
node.go
52 lines (41 loc) · 1012 Bytes
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package node
import (
"context"
"github.com/adlrocha/indexer-node/store"
"github.com/adlrocha/indexer-node/store/persistent"
"github.com/adlrocha/indexer-node/store/primary"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
)
var log = logging.Logger("node")
type Node struct {
primary store.Storage
persistent store.Storage
api *api
doneCh chan struct{}
}
func New(ctx context.Context, cctx *cli.Context) (*Node, error) {
// TODO: Create flag for the size of primary storage
e := cctx.String("endpoint")
var err error
n := new(Node)
n.doneCh = make(chan struct{})
n.primary = primary.New(1000000)
n.persistent = persistent.New()
err = n.initAPI(e)
if err != nil {
return nil, err
}
return n, nil
}
func (n *Node) Start() error {
log.Infow("Started server")
// TODO: Start required processes for stores
return n.api.Serve()
}
func (n *Node) Shutdown(ctx context.Context) error {
defer func() {
close(n.doneCh)
}()
return n.api.Shutdown(ctx)
}