added notification toasts (error modals still broken)
This commit is contained in:
42
internal/handlers/test.go
Normal file
42
internal/handlers/test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/view/page"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
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")
|
||||
title := r.Form.Get("title")
|
||||
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
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user