diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-08-05 21:26:50 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-08-05 21:26:57 -0400 |
commit | ca4465e1062a675fa60d50000ba73c3f08beec64 (patch) | |
tree | dd0f3c4b6f13d8e0ee8a88474e7ae1f6e1fad7f1 /main.go | |
parent | 033217721725f1824cf6c39b7daf232d3cc44a93 (diff) |
Use log_length constant
Fix bug when appending at filled logs
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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++ |