forked from trustwallet/blockatlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (50 loc) · 1.21 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/trustwallet/blockatlas/util"
"net/http"
"os"
)
var app = cobra.Command{
Use: "blockatlas [bind]",
Short: "BlockAtlas API server by TrustWallet",
Version: "indev",
Args: cobra.MaximumNArgs(1),
Run: run,
}
const defaultConfigName = "config.yml"
func main() {
app.Flags().StringP("config", "c", defaultConfigName, "Config file (optional)")
if err := app.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(cmd *cobra.Command, args []string) {
var bind string
if len(args) == 0 {
bind = ":8420"
} else {
bind = args[0]
}
confPath, _ := cmd.Flags().GetString("config")
loadConfig(confPath)
gin.SetMode(viper.GetString("gin.mode"))
router := gin.Default()
router.Use(util.CheckReverseProxy)
router.GET("/", getRoot)
router.GET("/status", func(c *gin.Context) {
c.JSON(http.StatusOK, map[string]interface{}{
"status": true,
})
})
loadPlatforms(router)
logrus.WithField("bind", bind).Info("Running application")
if err := router.Run(bind); err != nil {
logrus.WithError(err).Fatal("Application failed")
}
}