more diff
This commit is contained in:
parent
2c08c51c15
commit
7bc25acbb2
1 changed files with 26 additions and 0 deletions
26
api/logs.go
26
api/logs.go
|
@ -186,6 +186,32 @@ func (s *Server) getDatedUserLogs(c echo.Context) error {
|
|||
return c.String(http.StatusOK, content)
|
||||
}
|
||||
|
||||
if c.Request().Header.Get("Content-Type") == "application/json" {
|
||||
|
||||
openFile, err := os.Open(file)
|
||||
if err != nil {
|
||||
errJSON := new(ErrorJSON)
|
||||
errJSON.Error = "error finding logs"
|
||||
return c.JSON(http.StatusNotFound, errJSON)
|
||||
}
|
||||
defer openFile.Close()
|
||||
|
||||
scanner := bufio.NewScanner(openFile)
|
||||
|
||||
messages := []LogMessage{}
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
result := logReg.FindStringSubmatch(line)
|
||||
|
||||
message := LogMessage{Username: result[2], Message: result[3], Timestamp: result[1]}
|
||||
|
||||
messages = append(messages, message)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, messages)
|
||||
}
|
||||
|
||||
return c.File(file)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue