-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (46 loc) · 1.17 KB
/
main.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
package main
import (
"fmt"
"os"
"sync"
"github.com/TrueBlocks/trueblocks-node/v4/app"
sdk "github.com/TrueBlocks/trueblocks-sdk/v4"
)
func main() {
a := app.NewApp()
if cont, err := a.ParseArgs(); !cont {
return // don't continue
} else if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
// Establish the configuration file
if err := a.EstablishConfig(); err != nil {
a.Fatal(err)
} else {
a.Logger.Info("trueblocks-node", "scrape", a.State(app.Scrape), "api", a.State(app.Api), "monitor", a.State(app.Monitor), "init-mode", a.InitMode)
// Start the API server. It runs in its own goroutine.
var apiUrl string
if a.IsOn(app.Api) {
go sdk.StartApiServer(&apiUrl)
}
// Start forever loop to scrape and (optionally) monitor the chain
wg := sync.WaitGroup{}
if a.IsOn(app.Scrape) {
wg.Add(1)
a.Logger.Info("start scraper...")
go a.RunScraper(&wg)
a.Logger.Info("scraper started...")
}
if a.IsOn(app.Monitor) {
wg.Add(1)
a.Logger.Info("start monitors...")
go a.RunMonitor(&wg)
a.Logger.Info("monitors started...")
}
if len(apiUrl) > 0 {
a.Logger.Info("api is runing", "apiUrl", apiUrl)
}
wg.Wait()
}
}