Documentation ¶
Index ¶
- Constants
- func AllowedResponseCode(code int) bool
- func Html(w http.ResponseWriter, r *http.Request, tmpl string, data any)
- func Html500(w http.ResponseWriter, r *http.Request, err error)
- func HtmlNoContent(w http.ResponseWriter)
- func HtmlStatus(w http.ResponseWriter, r *http.Request, statusCode int, tmpl string, data any)
- func LoadTemplates() error
- func SetDebug(v bool)
- func SetFileSystem(fsys fs.FS)
Constants ¶
const HdrHtml = "text/html"
Variables ¶
This section is empty.
Functions ¶
func AllowedResponseCode ¶
AllowedResponseCode returns true if the code is a permitted response code, false otherwise.
func Html500 ¶
func Html500(w http.ResponseWriter, r *http.Request, err error)
Html500 renders the given error as Html. In production mode, this always renders a generic "server error" message. In isDebug, it returns the actual error from the caller.
func HtmlStatus ¶
HtmlStatus renders the given Html template by name. It attempts to gracefully handle any rendering errors to avoid partial responses sent to the response by writing to a buffer first, then flushing the buffer to the response.
If template rendering fails, a generic 500 page is returned. In dev mode, the error is included on the page. If flushing the buffer to the response fails, an error is logged, but no recovery is attempted.
The buffers are fetched via a sync.Pool to reduce allocations and improve performance.
func SetFileSystem ¶
Types ¶
This section is empty.