forked from FlowingSPDG/cs2-log-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csgolog_http.go
40 lines (36 loc) · 886 Bytes
/
csgolog_http.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
package csgologhttp
import (
"bufio"
"github.com/FlowingSPDG/csgo-log"
"github.com/gin-gonic/gin"
"log"
"net/http"
"strings"
)
func CSGOLogger(Handler func(csgolog.Message, *gin.Context)) gin.HandlerFunc {
return func(c *gin.Context) {
raw, err := c.GetRawData()
if err != nil {
log.Printf("Failed to get raw data : %v\n", err)
c.String(http.StatusInternalServerError, err.Error())
c.Abort()
return
}
csgolog.LogLinePattern = csgolog.HTTPLinePattern
sl := strings.NewReader(string(raw))
scanner := bufio.NewScanner(sl)
for scanner.Scan() {
// fmt.Println(scanner.Text())
msg, err := csgolog.Parse(scanner.Text())
if err != nil {
log.Printf("Failed to parse data : %v\n", err)
c.String(http.StatusInternalServerError, err.Error())
c.Abort()
return
}
Handler(msg, c)
}
c.String(http.StatusOK, "OK")
c.Abort()
}
}