diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-08-07 01:21:50 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-08-07 01:21:50 -0400 |
commit | 53a699d2b32a3d7a5268de7ac5b9c6daa0fc3975 (patch) | |
tree | 68f02d55abc33ad2d343d38237da58488da81aff /internal/api/handlers.go | |
parent | 4f5b40328ba6f699264b073910222f22c43add7b (diff) |
Use single log length const
Diffstat (limited to 'internal/api/handlers.go')
-rw-r--r-- | internal/api/handlers.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go index 6fb6361..45354aa 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -17,7 +17,7 @@ func init() { fs = http.FileServer(http.Dir("static")) } -const log_length = 100 +const LogLength = 100 type accessLog struct { ClientAddr string `json:"clientAddr"` @@ -26,7 +26,7 @@ type accessLog struct { HttpMethod string `json:"httpMethod"` } -func CreateFilesHandler(logs *[log_length]string, n *int, logChan chan string) http.HandlerFunc { +func CreateFilesHandler(logs *[LogLength]string, n *int, logChan chan string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { jsonData, _ := json.Marshal(accessLog{ ClientAddr: redactIP(r.RemoteAddr), @@ -40,7 +40,7 @@ func CreateFilesHandler(logs *[log_length]string, n *int, logChan chan string) h } } -func CreateGetLogs(logs *[log_length]string) http.HandlerFunc { +func CreateGetLogs(logs *[LogLength]string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { for _, s := range logs { fmt.Fprintln(w, s) @@ -48,7 +48,7 @@ func CreateGetLogs(logs *[log_length]string) http.HandlerFunc { } } -func CreateLoginHandler(logs *[log_length]string, n *int, logChan chan string) http.HandlerFunc { +func CreateLoginHandler(logs *[LogLength]string, n *int, logChan chan string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) if err != nil { @@ -89,17 +89,17 @@ func redactIP(input string) string { }) } -func addRotLog(logs *[log_length]string, last *int, parser chan string, value string) { +func addRotLog(logs *[LogLength]string, last *int, parser chan string, value string) { if strings.Contains(value, "\n") { for _, v := range strings.Split(value, "\n") { addRotLog(logs, last, parser, v) } } else { - if *last == log_length { - for i := 0; i < log_length-1; i++ { + if *last == LogLength { + for i := 0; i < LogLength-1; i++ { logs[i] = logs[i+1] } - logs[log_length-1] = value + logs[LogLength-1] = value parser <- value } else { logs[*last] = value |