-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
50 lines (41 loc) · 1.34 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
package main
import (
"flag"
"os"
"strconv"
"strings"
"time"
"bdo-rest-api/config"
"bdo-rest-api/handlers"
)
func main() {
flagCacheTTL := flag.Int("cachettl", 180, "Cache TTL in minutes")
flagMaintenanceTTL := flag.Int("maintenancettl", 5, "Allows to limit how frequently scraper can check for maintenance end in minutes")
flagPort := flag.Int("port", 8001, "Port to catch requests on")
flagProxy := flag.String("proxy", "", "Open proxy address to make requests to BDO servers")
flagRateLimit := flag.Int64("ratelimit", 512, "Maximum number of requests per minute per IP")
flagVerbose := flag.Bool("verbose", false, "Print out additional logs into stdout")
flag.Parse()
// Read port from flags and env
if *flagPort == 8001 && len(os.Getenv("PORT")) > 0 {
port, err := strconv.Atoi(os.Getenv("PORT"))
if nil != err {
port = 8001
}
config.SetPort(port)
} else {
config.SetPort(*flagPort)
}
// Read proxies from flags
if len(*flagProxy) > 0 {
config.SetProxyList(strings.Fields(*flagProxy))
} else {
config.SetProxyList(strings.Fields(os.Getenv("PROXY")))
}
config.SetCacheTTL(time.Duration(*flagCacheTTL) * time.Minute)
config.SetMaintenanceStatusTTL(time.Duration(*flagMaintenanceTTL) * time.Minute)
config.SetVerbosity(*flagVerbose)
config.SetRateLimit(*flagRateLimit)
config.PrintConfig()
handlers.ListenAndServe()
}