forked from ton-connect/bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (45 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
package main
import (
"fmt"
"github.com/tonkeeper/bridge/storage/memory"
"github.com/tonkeeper/bridge/storage/pg"
"net/http"
"github.com/tonkeeper/bridge/config"
_ "net/http/pprof"
"github.com/labstack/echo-contrib/prometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
func main() {
log.Info("Bridge is running")
config.LoadConfig()
var db db
var err error
if config.Config.DbURI != "" {
db, err = pg.NewStorage(config.Config.DbURI)
if err != nil {
log.Fatalf("db connection %v", err)
}
} else {
db = memory.NewStorage()
}
metricsMux := http.NewServeMux()
metricsMux.Handle("/metrics", promhttp.Handler())
go func() {
log.Fatal(http.ListenAndServe(":9103", metricsMux))
}()
e := echo.New()
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
Skipper: nil,
DisableStackAll: true,
DisablePrintStack: false,
}))
e.Use(middleware.Logger())
p := prometheus.NewPrometheus("http", nil)
p.Use(e)
h := newHandler(db)
registerHandlers(e, h)
log.Fatal(e.Start(fmt.Sprintf(":%v", config.Config.Port)))
}