-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
60 lines (44 loc) · 1.71 KB
/
server.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 NOMP_API
import (
"flag"
"fmt"
"log"
"net/http"
"NOMP-API/db"
"NOMP-API/nodes"
"NOMP-API/utils"
"github.com/Vilsol/GoLib"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func Serve() {
// Read flags
redisHost := flag.String("redis-host", "localhost", "Redis Host")
redisPort := flag.Int("redis-port", 6379, "Redis Port")
redisPassword := flag.String("redis-password", "", "Redis Password (default \"\")")
redisDb := flag.Int("redis-db", 0, "Redis DB (default 0)")
coin := flag.String("coin", "garlicoin", "Coin")
hashrateMultiplier := flag.Int("hashrate-multiplier", 65536, "Hashrate Multiplier")
hashrateWindow := flag.Int("hashrate-window", 300, "Hashrate Window")
historicalRetention := flag.Int("historical-retention", 43200, "Historical Retention Time")
listenPort := flag.Int("listen-port", 8080, "Listening Port")
flag.Parse()
utils.InitializeFlags(coin, hashrateMultiplier, hashrateWindow, historicalRetention)
db.InitializeRedis(*redisHost, *redisPort, *redisPassword, *redisDb)
router := mux.NewRouter()
router.NotFoundHandler = GoLib.LoggerHandler(GoLib.NotFoundHandler())
v1 := GoLib.RouteHandler(router, "/v1")
nodes.RegisterWorkerRoutes(v1)
nodes.RegisterEverythingRoutes(v1)
CORSHandler := handlers.CORS(
handlers.AllowedOrigins([]string{"*"}),
handlers.AllowedMethods([]string{"GET", "HEAD", "OPTIONS"}),
)
var finalRouter http.Handler = router
finalRouter = CORSHandler(finalRouter)
finalRouter = GoLib.LoggerHandler(finalRouter)
finalRouter = handlers.CompressHandler(finalRouter)
finalRouter = handlers.ProxyHeaders(finalRouter)
fmt.Printf("Listening on port %d\n", *listenPort)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *listenPort), finalRouter))
}