package ext import ( "bytes" "fmt" "github.com/valyala/fasthttp" "git.sr.ht/~gabrielgio/img/templates" ) var ( ContentTypeHTML = []byte("text/html") ) func NotFoundHTML(ctx *fasthttp.RequestCtx) { templates.WritePageTemplate(ctx, &templates.ErrorPage{ Err: "Not Found", }) } func NotFound(ctx *fasthttp.RequestCtx) { ctx.Response.SetStatusCode(404) ct := ctx.Response.Header.ContentType() if bytes.Equal(ct, ContentTypeHTML) { NotFoundHTML(ctx) } } func InternalServerError(ctx *fasthttp.RequestCtx, err error) { ctx.Response.SetStatusCode(500) templates.WritePageTemplate(ctx, &templates.ErrorPage{ Err: fmt.Sprintf("Internal Server Error:\n%s", err.Error()), }) } func NoContent(ctx *fasthttp.RequestCtx) { ctx.Response.SetStatusCode(204) }