summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2025-08-05 21:35:05 -0400
committerRobby Zambito <contact@robbyzambito.me>2025-08-05 21:36:13 -0400
commita3f0b458370b3f0b00ce2897053e5e4a4a6add27 (patch)
tree64f9f3236024c9ab52383f5acef287c3da2fdcfc /main.go
parentca4465e1062a675fa60d50000ba73c3f08beec64 (diff)
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.
Diffstat (limited to 'main.go')
-rw-r--r--main.go21
1 files 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++
+ }
}
}