52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.haelnorr.com/h/oslstats/internal/view/page"
|
|
"github.com/pkg/errors"
|
|
|
|
"git.haelnorr.com/h/golib/hws"
|
|
"git.haelnorr.com/h/golib/notify"
|
|
)
|
|
|
|
// Handles responses to the / path. Also serves a 404 Page for paths that
|
|
// don't have explicit handlers
|
|
func NotifyTester(server *hws.Server) http.Handler {
|
|
return http.HandlerFunc(
|
|
func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "GET" {
|
|
page.Test().Render(r.Context(), w)
|
|
} else {
|
|
r.ParseForm()
|
|
target := r.Form.Get("target")
|
|
title := r.Form.Get("title")
|
|
level := map[string]notify.Level{
|
|
"info": notify.LevelInfo,
|
|
"success": notify.LevelSuccess,
|
|
"warn": notify.LevelWarn,
|
|
"error": notify.LevelError,
|
|
}[r.Form.Get("type")]
|
|
error := errors.New("This is a stack trace. No really i swear. Just pretend ok? Thanks")
|
|
message := r.Form.Get("message")
|
|
nt := notify.Notification{
|
|
Target: notify.Target(target),
|
|
Title: title,
|
|
Message: message,
|
|
Level: level,
|
|
Details: error.Error(),
|
|
}
|
|
if target == "" {
|
|
server.NotifyAll(nt)
|
|
} else {
|
|
server.NotifySub(nt)
|
|
}
|
|
}
|
|
},
|
|
)
|
|
}
|
|
|
|
func notifyInfoWS() {
|
|
|
|
}
|