-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (45 loc) · 1.3 KB
/
main.go
File metadata and controls
52 lines (45 loc) · 1.3 KB
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
package main
import (
"ReviveProject/src"
"flag"
"fmt"
"istio.io/pkg/cache"
"os"
"strconv"
"time"
)
func main() {
port := flag.Int("port", 8000, "Port to listen to")
key := flag.String("key", "", "Hypixel API-Key")
endpointsFile := flag.String("endpoints", "./endpoints.json", "File location where all endpoints are saved")
cacheTime := flag.Int("cache", 60, "Time in seconds for global memory cache to speedup repeated requests")
flag.Parse()
if *port <= 0 || *port > 65536 {
fmt.Println("port must be 0-65536. Given " + strconv.Itoa(*port))
flag.PrintDefaults()
return
}
if !(len(*key) >= 32 && len(*key) <= 36) {
fmt.Println("key must be a valid UUID4. Given " + *key)
flag.PrintDefaults()
return
}
if *cacheTime < 0 {
fmt.Println("cache must be equal or bigger than 0. Given " + strconv.Itoa(*cacheTime))
flag.PrintDefaults()
return
}
start(*port, *key, *endpointsFile, *cacheTime)
}
func start(port int, key string, endpointsFile string, cacheTime int) {
expiringCache := cache.NewLRU(time.Duration(cacheTime)*time.Second,
time.Duration(cacheTime/2)*time.Second,
500)
hypixel := src.NewHypixelApi(key)
manager, err := src.NewEndPointManager(endpointsFile)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
return
}
src.Listen(*manager, hypixel, expiringCache, port)
}