diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -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++ + } } } |