-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
72 lines (63 loc) · 1.44 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/oysterprotocol/brokernode/actions"
"github.com/oysterprotocol/brokernode/utils"
"log"
"math/rand"
"os"
"runtime"
"time"
"github.com/gobuffalo/pop"
"github.com/gobuffalo/pop/logging"
)
var popLog = false
var oysterLogger = func(lvl logging.Level, s string, args ...interface{}) {
if lvl == logging.SQL {
if len(args) > 0 {
xargs := make([]string, len(args))
for i, a := range args {
switch a.(type) {
case string:
xargs[i] = fmt.Sprintf("%q", a)
default:
xargs[i] = fmt.Sprintf("%v", a)
}
}
s = fmt.Sprintf("%s - %s | %s", lvl, s, xargs)
} else {
s = fmt.Sprintf("%s - %s", lvl, s)
}
} else {
s = fmt.Sprintf(s, args...)
s = fmt.Sprintf("%s - %s", lvl, s)
}
if pop.Color {
s = color.YellowString(s)
}
if popLog {
fmt.Println(s)
}
}
func main() {
// Allow running on multiple cores. Kinda weird that this is manual?
// https://golang.org/pkg/runtime/#GOMAXPROCS
runtime.GOMAXPROCS(runtime.NumCPU())
pop.Debug = false
pop.SetLogger(oysterLogger)
// Setup rand. See https://til.hashrocket.com/posts/355f31f19c-seeding-golangs-rand
rand.Seed(time.Now().Unix())
app := actions.App()
defer oyster_utils.CloseKvStore()
if os.Getenv("DATA_MAPS_IN_BADGER") != "true" {
// Setup KV Store
err := oyster_utils.InitKvStore()
if err != nil {
log.Fatal(err)
}
}
if err := app.Serve(); err != nil {
log.Fatal(err)
}
}