diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-08-06 13:54:31 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-08-06 14:14:21 -0400 |
commit | 77c49c4c86130385065b940b75282d1745a6473f (patch) | |
tree | 590754f9a21bc31e9378a6361f79dbdb74c798f1 /main.go | |
parent | 247bc655b38ad27f6007b9aaf4ede1c2a97bf32d (diff) |
uhh did stuff to make logging better i think
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 26 |
1 files changed, 10 insertions, 16 deletions
@@ -21,11 +21,11 @@ type accessLog struct { } type loginAttemptLog struct { - Email string `json:"email"` - Password string `json:"password"` - LoginTime time.Time `json:"loginTime"` - Success bool `json:"success"` - RememberMe bool `json:"rememberMe"` + Email json.RawMessage `json:"email"` + Password string `json:"password"` + LoginTime time.Time `json:"loginTime"` + Success bool `json:"success"` + RememberMe bool `json:"rememberMe"` } func main() { @@ -55,24 +55,17 @@ func main() { defer r.Body.Close() err := json.Unmarshal([]byte(body), &data) if err != nil { - http.Error(w, "Bad request", http.StatusBadRequest) + addRotLog(&logs, &n, string(body)) + http.Error(w, "Forbidden", http.StatusForbidden) return } if email, ok := data["email"].(string); ok { if rememberMe, ok := data["rememberMe"].(bool); ok { - jsonData, _ := json.Marshal(loginAttemptLog{ - Email: email, - Password: "XXXXXXXX", - LoginTime: time.Now().UTC(), - Success: false, - RememberMe: rememberMe, - }) - - addRotLog(&logs, &n, string(jsonData)) - http.Error(w, "Forbidden", http.StatusForbidden) + addRotLog(&logs, &n, fmt.Sprintf(`{"email": "%s", "password": "XXXXXXXX", "loginTime": "%s", "success": false, "rememberMe": %t}`, email, time.Now().UTC(), rememberMe)) } } + http.Error(w, "Forbidden", http.StatusForbidden) }) @@ -93,6 +86,7 @@ func createGetLogs(logs *[log_length]string) func(http.ResponseWriter, *http.Req } func addRotLog(logs *[log_length]string, last *int, value string) { + // fmt.Printf("%d %t %s\n", *last, strings.Contains(value, "\n"), value) if strings.Contains(value, "\n") { for _, v := range strings.Split(value, "\n") { addRotLog(logs, last, v) |