summaryrefslogtreecommitdiff
path: root/internal/api/handlers.go
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2025-08-07 21:36:24 -0400
committerRobby Zambito <contact@robbyzambito.me>2025-08-08 11:40:59 -0400
commit0c4d50017842ee2bd07f6a0fcc7c8b28fb3a5345 (patch)
treec58a10432d356475de3ff2fa25724a6837e788f6 /internal/api/handlers.go
parentf0e918354bc27525e49ee4b4794fe44ff605f046 (diff)
Rename logChan to toLogParser
Better description
Diffstat (limited to 'internal/api/handlers.go')
-rw-r--r--internal/api/handlers.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go
index 7f8f5d1..97cd569 100644
--- a/internal/api/handlers.go
+++ b/internal/api/handlers.go
@@ -44,7 +44,7 @@ type accessLog struct {
HttpMethod string `json:"httpMethod"`
}
-func CreateFilesHandler(logs *[LogLength]string, n *int, logChan chan string) http.HandlerFunc {
+func CreateFilesHandler(logs *[LogLength]string, n *int, toLogParser chan string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
jsonData, _ := json.Marshal(accessLog{
ClientAddr: redactIP(r.RemoteAddr),
@@ -52,7 +52,7 @@ func CreateFilesHandler(logs *[LogLength]string, n *int, logChan chan string) ht
RequestTime: time.Now().UTC(),
HttpMethod: r.Method,
})
- addRotLog(logs, n, logChan, string(jsonData))
+ addRotLog(logs, n, toLogParser, string(jsonData))
// Serve the index.html file from the static directory
http.StripPrefix("/", fs).ServeHTTP(w, r)
}
@@ -66,7 +66,7 @@ func CreateGetLogs(logs *[LogLength]string) http.HandlerFunc {
}
}
-func CreateLoginHandler(logs *[LogLength]string, n *int, logChan chan string) http.HandlerFunc {
+func CreateLoginHandler(logs *[LogLength]string, n *int, toLogParser chan string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
@@ -77,14 +77,14 @@ func CreateLoginHandler(logs *[LogLength]string, n *int, logChan chan string) ht
var data map[string]any
if json.Unmarshal(body, &data) != nil {
- addRotLog(logs, n, logChan, fmt.Sprintf(`{"authRequest": %s}`, string(body)))
+ addRotLog(logs, n, toLogParser, fmt.Sprintf(`{"authRequest": %s}`, string(body)))
http.Error(w, `{"message": "Unauthorized"}`, http.StatusUnauthorized)
return
}
if email, ok := data["email"].(string); ok {
if rememberMe, ok := data["rememberMe"].(bool); ok {
- addRotLog(logs, n, logChan, fmt.Sprintf(`{"authRequest": {"email": "%s", "password": "XXXXXXXX", "loginTime": "%s", "success": false, "rememberMe": %t}}`, email, time.Now().UTC(), rememberMe))
+ addRotLog(logs, n, toLogParser, fmt.Sprintf(`{"authRequest": {"email": "%s", "password": "XXXXXXXX", "loginTime": "%s", "success": false, "rememberMe": %t}}`, email, time.Now().UTC(), rememberMe))
}
}
http.Error(w, `{"message": "Unauthorized"}`, http.StatusUnauthorized)
@@ -337,7 +337,7 @@ func StatusUptimeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(jsonData))
}
-func CreateStatusSubscribeHandler(logs *[LogLength]string, n *int, logChan chan string) http.HandlerFunc {
+func CreateStatusSubscribeHandler(logs *[LogLength]string, n *int, toLogParser chan string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
@@ -346,12 +346,12 @@ func CreateStatusSubscribeHandler(logs *[LogLength]string, n *int, logChan chan
}
defer r.Body.Close()
- addRotLog(logs, n, logChan, fmt.Sprintf(`{"subscribeEmails": %s}`, string(body)))
+ addRotLog(logs, n, toLogParser, fmt.Sprintf(`{"subscribeEmails": %s}`, string(body)))
fmt.Fprint(w, "{}")
}
}
-func CreateContactHandler(logs *[LogLength]string, n *int, logChan chan string) http.HandlerFunc {
+func CreateContactHandler(logs *[LogLength]string, n *int, toLogParser chan string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
@@ -360,7 +360,7 @@ func CreateContactHandler(logs *[LogLength]string, n *int, logChan chan string)
}
defer r.Body.Close()
- addRotLog(logs, n, logChan, fmt.Sprintf(`{"contactMessage": %s}`, string(body)))
+ addRotLog(logs, n, toLogParser, fmt.Sprintf(`{"contactMessage": %s}`, string(body)))
fmt.Fprint(w, "{}")
}
}