From a3f0b458370b3f0b00ce2897053e5e4a4a6add27 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Tue, 5 Aug 2025 21:35:05 -0400 Subject: Added support for newlines logs added with newlines in the value will be added as seperate values in the log array Testing with \\n for inserting \n in the output, that works fine. --- main.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index d56f82d..f56cda1 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "net/http" + "strings" ) const log_length = 100 @@ -15,7 +16,7 @@ func main() { // Define a handler function for the root path http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - addRotLog(&logs, &n, fmt.Sprintf("Accessed %s", r.URL.Path)) + addRotLog(&logs, &n, fmt.Sprintf("Accessed %s", r.URL.Path, x, n)) // Serve the index.html file from the static directory http.StripPrefix("/", fs).ServeHTTP(w, r) }) @@ -43,13 +44,19 @@ func createGetLogs(logs *[log_length]string) func(http.ResponseWriter, *http.Req } func addRotLog(logs *[log_length]string, last *int, value string) { - if *last == log_length { - for i := 0 ; i < log_length-1; i++ { - logs[i] = logs[i+1] + if strings.Contains(value, "\n") { + for _, v := range strings.Split(value, "\n") { + addRotLog(logs, last, v) } - logs[log_length-1] = value } else { - logs[*last] = value - *last++ + if *last == log_length { + for i := 0 ; i < log_length-1; i++ { + logs[i] = logs[i+1] + } + logs[log_length-1] = value + } else { + logs[*last] = value + *last++ + } } } -- cgit