feat(smalltrip,problem): handler browser

This commit is contained in:
Guz
2025-07-30 19:14:43 -03:00
parent 6fca911c8f
commit 47670daf55

View File

@@ -4,20 +4,29 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"io"
"net/http"
"strings"
)
type Handler func(p Problem) http.Handler
func HandlerAll(p Problem) http.Handler {
h := HandlerContentType(map[string]Handler{
"application/xml": HandlerXML,
ProblemMediaTypeXML: HandlerXML,
"application/json": HandlerJSON,
ProblemMediaTypeJSON: HandlerJSON,
}, HandlerJSON)
return h(p)
// TODO: HandlerDevpage, this handler will be a complete handler with the smalltrip logo and a stylized page showing the error, JSON and XML values, and accepting a custom
// template to add custom styling.
func HandlerBrowser(template Template) Handler {
return func(p Problem) http.Handler {
h := HandlerContentType(map[string]Handler{
"text/html": HandlerTemplate(template),
"application/xml+html": HandlerTemplate(template),
"application/xml": HandlerXML,
ProblemMediaTypeXML: HandlerXML,
"application/json": HandlerJSON,
ProblemMediaTypeJSON: HandlerJSON,
}, HandlerJSON)
return h(p)
}
}
func HandlerTemplate(template Template) Handler {
return func(p Problem) http.Handler {