fix: remove logging from utils
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 44s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 50s

This commit was merged in pull request #292.
This commit is contained in:
2024-12-04 21:23:19 +01:00
parent 9e8e595258
commit 5198487feb
8 changed files with 74 additions and 74 deletions

View File

@@ -1,44 +1,18 @@
package utils
import (
"me-fit/log"
"fmt"
"log/slog"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type ContextKey string
const (
ContextKeyUser ContextKey = "user_id"
)
var (
errorMetric = promauto.NewCounter(
prometheus.CounterOpts{
Name: "mefit_error_total",
Help: "The total number of errors during processing",
},
)
)
func LogError(message string, err error) {
slog.Error(message + ": " + err.Error())
errorMetric.Inc()
}
func LogErrorMsg(message string) {
slog.Error(message)
errorMetric.Inc()
}
func TriggerToast(w http.ResponseWriter, r *http.Request, class string, message string) {
if isHtmx(r) {
w.Header().Set("HX-Trigger", fmt.Sprintf(`{"toast": "%v|%v"}`, class, message))
} else {
LogErrorMsg("Trying to trigger toast in non-HTMX request")
log.ErrorMsg("Trying to trigger toast in non-HTMX request")
}
}