mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-05 08:16:55 +08:00
Logs refactoring after #780
This commit is contained in:
@@ -254,35 +254,15 @@ func restartHandler(w http.ResponseWriter, r *http.Request) {
|
||||
go shell.Restart()
|
||||
}
|
||||
|
||||
// logHandler handles HTTP requests for log buffer operations.
|
||||
// It supports two HTTP methods:
|
||||
// - GET: Retrieves the content of in-memory log and sends it back to the client as plain text.
|
||||
// - DELETE: Clear the in-memory log buffer.
|
||||
//
|
||||
// The function expects a valid http.ResponseWriter and an http.Request as parameters.
|
||||
// For a GET request, it reads the log from in-memory buffer and writes
|
||||
// the content to the response writer with a "text/plain" content type.
|
||||
//
|
||||
// For a DELETE request, it clears the in-memory buffer.
|
||||
//
|
||||
// For any other HTTP method, it responds with an HTTP 400 (Bad Request) status.
|
||||
//
|
||||
// Parameters:
|
||||
// - w http.ResponseWriter: The response writer to write the HTTP response to.
|
||||
// - r *http.Request: The HTTP request object containing the request details.
|
||||
//
|
||||
// No return values are provided since the function writes directly to the response writer.
|
||||
func logHandler(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
|
||||
// Send current state of the log file immediately
|
||||
data := app.LogCollector.Bytes()
|
||||
Response(w, data, "text/plain")
|
||||
w.Header().Set("Content-Type", "application/jsonlines")
|
||||
_, _ = app.MemoryLog.WriteTo(w)
|
||||
case "DELETE":
|
||||
app.LogCollector.Reset()
|
||||
|
||||
Response(w, "Log truncated", "text/plain")
|
||||
app.MemoryLog.Reset()
|
||||
Response(w, "OK", "text/plain")
|
||||
default:
|
||||
http.Error(w, "Method not allowed", http.StatusBadRequest)
|
||||
}
|
||||
|
Reference in New Issue
Block a user