package ext import ( "bytes" "fmt" "github.com/valyala/fasthttp" "git.sr.ht/~gabrielgio/img" ) var ( ContentTypeJSON = []byte("application/json") ContentTypeHTML = []byte("text/html") ContentTypeMARKDOWN = []byte("text/markdown") ContentTypeJPEG = []byte("image/jpeg") ) func NotFoundHTML(ctx *fasthttp.RequestCtx) { ctx.Response.Header.SetContentType("text/html") //nolint:errcheck img.Render(ctx, "error.html", &img.HTMLView[string]{ Data: "NotFound", }) } 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.Header.SetContentType("text/html") message := fmt.Sprintf("Internal Server Error:\n%+v", err) //nolint:errcheck respErr := img.Render(ctx, "error.html", &img.HTMLView[string]{ Data: message, }) if respErr != nil { fmt.Println(respErr.Error()) } } func NoContent(ctx *fasthttp.RequestCtx) { ctx.Response.SetStatusCode(204) }