-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
89 lines (68 loc) · 2.64 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
HNTScan.io
Powered by Hotspotty.net
*/
package main
import (
"flag"
"hntscan/db"
"hntscan/handlers"
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
// Start database connection
db.Start()
// Get parameter to know if running on dev or production
DEV := flag.Bool("dev", false, "Run in development mode")
flag.Parse()
serverPort := ":1122"
if *DEV {
serverPort = ":8082"
}
e := echo.New()
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_custom} [${method}][${uri}] - ${remote_ip} - ${user_agent} ${status} - ${latency_human}\n",
CustomTimeFormat: "2006-01-02 15:04:05",
}))
e.Pre(middleware.AddTrailingSlash())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "HNTScan V1")
})
apiGroup := e.Group("/api/v1")
apiGroup.GET("/search/:query/", handlers.Search)
/* HOMEPAGE STATS */
apiGroup.GET("/stats/overview/", handlers.GetStatsOverview)
/* BLOCKS */
apiGroup.GET("/blocks/", handlers.GetBlocks)
apiGroup.GET("/blocks/:block/", handlers.GetSingleBlock)
/* TRANSACTIONS */
apiGroup.GET("/transactions/", handlers.GetTransactions)
apiGroup.GET("/transactions/:tx/", handlers.GetSingleTransaction)
apiGroup.GET("/transactions/:tx/rewards/", handlers.GetRewardTxPagination)
/* HOTSPOTS */
apiGroup.GET("/hotspots/", handlers.GetHotspots)
apiGroup.GET("/hotspots/:hash/", handlers.GetSingleHotspot)
apiGroup.GET("/hotspots/activities/:hash/", handlers.GetSingleHotspotActivities)
apiGroup.GET("/hotspots/avgbeacons/:hash/", handlers.GetSingleHotspotAvgBeacons)
apiGroup.GET("/hotspots/status/:hash/", handlers.GetSingleHotspotStatus)
apiGroup.POST("/hotspots/status/", handlers.GetMultipleHotspotStatus)
apiGroup.GET("/hotspots/rewards/:hash/:days/", handlers.GetSingleHotspotRewards)
/* WALLETS */
apiGroup.GET("/wallets/", handlers.GetWallets)
apiGroup.GET("/wallets/:hash/", handlers.GetSingleWallets)
apiGroup.GET("/wallets/:hash/hotspots/", handlers.GetSingleWalletHotspots)
apiGroup.GET("/wallets/:hash/validators/", handlers.GetSingleWalletValidators)
/* VALIDATORS */
apiGroup.GET("/validators/", handlers.GetValidators)
apiGroup.GET("/validators/:hash/", handlers.GetSingleValidator)
/* PRICES */
apiGroup.GET("/price/oracle/", handlers.GetOraclePrices)
e.Logger.Fatal(e.Start(serverPort))
}