fix: remove logging from utils
This commit was merged in pull request #292.
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user