-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (38 loc) · 864 Bytes
/
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
package main
import (
"DcCheckerStatus/antiflood"
"DcCheckerStatus/consts"
"DcCheckerStatus/handlers"
"DcCheckerStatus/http/webserver"
"DcCheckerStatus/ipinfo"
"github.com/valyala/fasthttp"
)
var ipInfo *ipinfo.Context
var antiFlood *antiflood.Context
func main() {
consts.LoadEnv()
client := webserver.Client(onMessage)
ipInfo = ipinfo.Client()
antiFlood = antiflood.Client()
go ipInfo.Run()
client.Run()
}
func onMessage(ctx *fasthttp.RequestCtx) {
ip := string(ctx.Request.Header.Peek("X-Forwarded-For"))
if antiFlood.CheckFlood(ip) {
switch string(ctx.Path()) {
case "/sendData":
handlers.SendData(ip, ctx, ipInfo)
break
case "/getScore":
handlers.GetScore(ip, ctx, ipInfo)
break
default:
handlers.NotFound(ctx)
break
}
} else {
ctx.SetStatusCode(fasthttp.StatusTooManyRequests)
ctx.SetConnectionClose()
}
}