lens @ 398ae343e6a33fb81f82380b17081b8f9bae328a

 1package ext
 2
 3import (
 4	"bytes"
 5	"fmt"
 6
 7	"github.com/valyala/fasthttp"
 8
 9	"git.sr.ht/~gabrielgio/img/templates"
10)
11
12var (
13	ContentTypeHTML = []byte("text/html")
14)
15
16func NotFoundHTML(ctx *fasthttp.RequestCtx) {
17	templates.WritePageTemplate(ctx, &templates.ErrorPage{
18		Err: "Not Found",
19	})
20}
21
22func NotFound(ctx *fasthttp.RequestCtx) {
23	ctx.Response.SetStatusCode(404)
24	ct := ctx.Response.Header.ContentType()
25	if bytes.Equal(ct, ContentTypeHTML) {
26		NotFoundHTML(ctx)
27	}
28}
29
30func InternalServerError(ctx *fasthttp.RequestCtx, err error) {
31	ctx.Response.SetStatusCode(500)
32	templates.WritePageTemplate(ctx, &templates.ErrorPage{
33		Err: fmt.Sprintf("Internal Server Error:\n%s", err.Error()),
34	})
35}
36
37func NoContent(ctx *fasthttp.RequestCtx) {
38	ctx.Response.SetStatusCode(204)
39}