-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (82 loc) · 2.16 KB
/
main.go
File metadata and controls
88 lines (82 loc) · 2.16 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"github.com/olivere/elastic/v7"
"github.com/sirupsen/logrus"
"github.com/tezoscommons/tezos-ipfs/cmd"
"github.com/tezoscommons/tezos-ipfs/internal/tezosipfs/app"
"github.com/tezoscommons/tezos-ipfs/internal/tezosipfs/cache"
"github.com/tezoscommons/tezos-ipfs/internal/tezosipfs/config"
"github.com/tezoscommons/tezos-ipfs/internal/tezosipfs/crypto"
"github.com/tezoscommons/tezos-ipfs/internal/tezosipfs/db"
"github.com/tezoscommons/tezos-ipfs/internal/tezosipfs/network"
"github.com/tezoscommons/tezos-ipfs/internal/tezosipfs/swarm"
"go.uber.org/dig"
"gopkg.in/sohlich/elogrus.v7"
"io"
"log"
"os"
"strings"
"time"
)
func main() {
c := dig.New()
c.Provide(config.NewConfig)
c.Provide(network.NewIPFS)
c.Provide(network.NewLightclient)
c.Provide(db.NewStormDB)
c.Provide(crypto.GetPrivateKey)
c.Provide(cache.NewS3Cache)
c.Provide(app.NewGateway)
c.Provide(network.GetNetwork)
c.Provide(swarm.NewSwarm)
c.Provide(GetLog)
c.Provide(app.NewPinManager)
c.Provide(app.NewAdminAPI)
rootCmd := cmd.GetRootCommand(c)
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func GetLog(c *config.Config) *logrus.Entry {
l := logrus.New()
if c.Log.Elasticsearch != "" {
client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200"))
if err != nil {
log.Fatal(err)
}
hook, err := elogrus.NewAsyncElasticHook(client, "localhost", logrus.DebugLevel, "tezos-ipfs")
if err != nil {
log.Fatal(err)
}
l.AddHook(hook)
}
if c.Log.File != "" {
logFile, e := os.OpenFile(c.Log.File, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if e != nil {
fmt.Println(e)
}
mw := io.MultiWriter(os.Stdout, logFile)
l.SetOutput(mw)
}
switch strings.ToLower(c.Log.Level) {
case "debug":
l.SetLevel(logrus.DebugLevel)
case "trace":
l.SetLevel(logrus.TraceLevel)
case "info":
l.SetLevel(logrus.InfoLevel)
case "warn":
l.SetLevel(logrus.WarnLevel)
default:
l.SetLevel(logrus.InfoLevel)
}
if c.Log.Format == "text" {
l.SetFormatter(&logrus.TextFormatter{})
}
if c.Log.Format == "json" {
l.SetFormatter(&logrus.JSONFormatter{})
}
return l.WithField("starttime", time.Now().Unix())
}