51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.haelnorr.com/h/golib/hws"
|
|
"git.haelnorr.com/h/golib/notify"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func notifyClient(
|
|
s *hws.Server,
|
|
r *http.Request,
|
|
level notify.Level,
|
|
title, message, details string,
|
|
action any,
|
|
) error {
|
|
subCookie, err := r.Cookie("ws_sub_id")
|
|
if err != nil {
|
|
return errors.Wrap(err, "r.Cookie")
|
|
}
|
|
subID := notify.Target(subCookie.Value)
|
|
nt := notify.Notification{
|
|
Target: subID,
|
|
Title: title,
|
|
Message: message,
|
|
Details: details,
|
|
Action: action,
|
|
Level: level,
|
|
}
|
|
s.NotifySub(nt)
|
|
return nil
|
|
}
|
|
|
|
func notifyInternalServiceError(s *hws.Server, r *http.Request, msg string, err error) error {
|
|
return notifyClient(s, r, notify.LevelError, "Internal Service Error", msg,
|
|
SerializeErrorDetails(http.StatusInternalServerError, err), nil)
|
|
}
|
|
|
|
func notifyWarn(s *hws.Server, r *http.Request, title, msg string, action any) error {
|
|
return notifyClient(s, r, notify.LevelWarn, title, msg, "", action)
|
|
}
|
|
|
|
func notifyInfo(s *hws.Server, r *http.Request, title, msg string, action any) error {
|
|
return notifyClient(s, r, notify.LevelInfo, title, msg, "", action)
|
|
}
|
|
|
|
func notifySuccess(s *hws.Server, r *http.Request, title, msg string, action any) error {
|
|
return notifyClient(s, r, notify.LevelSuccess, title, msg, "", action)
|
|
}
|