-
Notifications
You must be signed in to change notification settings - Fork 0
/
arkstat.go
58 lines (48 loc) · 1.25 KB
/
arkstat.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
53
54
55
56
57
58
package main
import (
"log"
"github.com/arken/arkstat/config"
"github.com/arken/arkstat/database"
"github.com/arken/arkstat/ipfs"
"github.com/arken/arkstat/mail"
"github.com/arken/arkstat/stats"
"github.com/arken/arkstat/tasks"
"github.com/arken/arkstat/web"
)
func main() {
err := config.Init()
if err != nil {
log.Fatal(err)
}
// Setup Database
db, err := database.Open(config.Global.Database.Path)
if err != nil {
log.Fatal(err)
}
// Setup IPFS Node
node, err := ipfs.CreateNode(config.Global.Ipfs.Path, ipfs.NodeConfArgs{
Addr: config.Global.Ipfs.Addr,
PeerID: config.Global.Ipfs.PeerID,
PrivKey: config.Global.Ipfs.PrivateKey,
SwarmKey: config.Manifest.ClusterKey,
BootstrapPeers: config.Manifest.BootstrapPeers,
})
if err != nil {
log.Fatal(err)
}
mailbox, err := mail.Init(config.Global.Mail.Domain,
config.Global.Mail.PrivateKey,
config.Global.Mail.Sender,
)
if err != nil {
log.Fatal(err)
}
// Setup Stats IPFS protocol handler
node.SetHandler("/arkstat/0.0.1", ipfs.BuildStatsHandler(db, mailbox))
// Initialize Stats Structure
stats := stats.Stats{}
// Startup background tasks
go tasks.Start(db, &stats, mailbox)
// Setup HTTP Server
web.Start(config.Global.Web.Addr, &stats)
}