move upstream into own package

This commit is contained in:
6543 2021-12-05 14:47:33 +01:00
parent f35c4d0f66
commit 38426c26db
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
7 changed files with 321 additions and 288 deletions

23
html/error.go Normal file
View file

@ -0,0 +1,23 @@
package html
import (
"bytes"
"github.com/valyala/fasthttp"
"strconv"
)
// ReturnErrorPage sets the response status code and writes NotFoundPage to the response body, with "%status" replaced
// with the provided status code.
func ReturnErrorPage(ctx *fasthttp.RequestCtx, code int) {
ctx.Response.SetStatusCode(code)
ctx.Response.Header.SetContentType("text/html; charset=utf-8")
message := fasthttp.StatusMessage(code)
if code == fasthttp.StatusMisdirectedRequest {
message += " - domain not specified in <code>.domains</code> file"
}
if code == fasthttp.StatusFailedDependency {
message += " - target repo/branch doesn't exist or is private"
}
// TODO: use template engine?
ctx.Response.SetBody(bytes.ReplaceAll(NotFoundPage, []byte("%status"), []byte(strconv.Itoa(code)+" "+message)))
}