From 8293c81319004aa76eb2991894a70b0496ff5bc0 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Wed, 6 Aug 2025 15:59:19 -0400 Subject: Wrap auth requests in authRequest object Remove debug prints --- main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 56e3b51..aef29cb 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,9 @@ import ( "time" ) +// Example: +// curl 'http://localhost:8080/v1/auth/login' -X POST -H 'Content-Type: application/json' --data-raw $'{}}\n{"king": 5' + const log_length = 100 type accessLog struct { @@ -61,15 +64,14 @@ func main() { // Attempt to parse JSON (optional, if you still want to try) var data map[string]any if json.Unmarshal(body, &data) != nil { - addRotLog(&logs, &n, string(body)) // Logs unmodified string + addRotLog(&logs, &n, fmt.Sprintf(`{"authRequest": %s}`, string(body))) // Logs unmodified string http.Error(w, "Forbidden", http.StatusForbidden) return } if email, ok := data["email"].(string); ok { if rememberMe, ok := data["rememberMe"].(bool); ok { - fmt.Println("Successfully unmarshalled json") - addRotLog(&logs, &n, fmt.Sprintf(`{"email": "%s", "password": "XXXXXXXX", "loginTime": "%s", "success": false, "rememberMe": %t}`, email, time.Now().UTC(), rememberMe)) + addRotLog(&logs, &n, fmt.Sprintf(`{"authRequest": {"email": "%s", "password": "XXXXXXXX", "loginTime": "%s", "success": false, "rememberMe": %t}}`, email, time.Now().UTC(), rememberMe)) } } http.Error(w, "Forbidden", http.StatusForbidden) @@ -93,7 +95,6 @@ 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 %v\n", *last, strings.Contains(value, "\n"), value) if strings.Contains(value, "\n") { for _, v := range strings.Split(value, "\n") { addRotLog(logs, last, v) -- cgit