diff options
-rw-r--r-- | internal/api/handlers.go | 16 | ||||
-rw-r--r-- | main.go | 4 |
2 files changed, 9 insertions, 11 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 @@ -12,8 +12,6 @@ import ( // Example: // curl 'http://localhost:8080/api/v1/auth/login' -X POST -H 'Content-Type: application/json' --data-raw $'{}}\n{"king": "key"' -const log_length = 100 - type loginAttemptLog struct { Email string `json:"email"` Password string `json:"password"` @@ -23,7 +21,7 @@ type loginAttemptLog struct { } func main() { - var logs [log_length]string + var logs [api.LogLength]string n := 0 king := "NOKING" |