we now got websockets baby

This commit is contained in:
2026-01-26 00:29:57 +11:00
parent ce524702f0
commit a3dafa592b
23 changed files with 621 additions and 312 deletions

View File

@@ -7,36 +7,45 @@ import (
"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 Test(server *hws.Server) http.Handler {
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()
notifytype := r.Form.Get("type")
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")
switch notifytype {
case "error":
err := errors.New(message)
notifyInternalServiceError(server, w, title, err)
return
case "warn":
notifyWarning(w, title, message)
return
case "info":
notifyInfo(w, title, message)
return
case "success":
notifySuccess(w, title, message)
return
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() {
}