From ca4465e1062a675fa60d50000ba73c3f08beec64 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Tue, 5 Aug 2025 21:26:50 -0400 Subject: Use log_length constant Fix bug when appending at filled logs --- main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index e6d3c44..d56f82d 100644 --- a/main.go +++ b/main.go @@ -5,10 +5,12 @@ import ( "net/http" ) +const log_length = 100 + func main() { fs := http.FileServer(http.Dir("static")) - var logs [100]string + var logs [log_length]string n := 0 // Define a handler function for the root path @@ -32,7 +34,7 @@ func main() { } } -func createGetLogs(logs *[100]string) func(http.ResponseWriter, *http.Request) { +func createGetLogs(logs *[log_length]string) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { for _, s := range logs { fmt.Fprintln(w, s) @@ -40,11 +42,12 @@ func createGetLogs(logs *[100]string) func(http.ResponseWriter, *http.Request) { } } -func addRotLog(logs *[100]string, last *int, value string) { - if *last == 100 { - for i := 0 ; i < 99; i++ { +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] } + logs[log_length-1] = value } else { logs[*last] = value *last++ -- cgit