mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 14:26:58 +00:00
more string
This commit is contained in:
parent
662d76386c
commit
51ca74fc11
16 changed files with 121 additions and 123 deletions
|
@ -1,9 +1,9 @@
|
|||
package html
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func errorMessage(statusCode int) string {
|
||||
|
@ -20,8 +20,8 @@ func errorMessage(statusCode int) string {
|
|||
}
|
||||
|
||||
// TODO: use template engine?
|
||||
func errorBody(statusCode int) []byte {
|
||||
return bytes.ReplaceAll(NotFoundPage,
|
||||
[]byte("%status"),
|
||||
[]byte(strconv.Itoa(statusCode)+" "+errorMessage(statusCode)))
|
||||
func errorBody(statusCode int) string {
|
||||
return strings.ReplaceAll(NotFoundPage,
|
||||
"%status",
|
||||
strconv.Itoa(statusCode)+" "+errorMessage(statusCode))
|
||||
}
|
||||
|
|
|
@ -13,5 +13,5 @@ func ReturnErrorPage(ctx *fasthttp.RequestCtx, code int) {
|
|||
ctx.Response.Header.SetContentType("text/html; charset=utf-8")
|
||||
|
||||
// TODO: use template engine?
|
||||
ctx.Response.SetBody(errorBody(code))
|
||||
ctx.Response.SetBody([]byte(errorBody(code)))
|
||||
}
|
||||
|
|
|
@ -3,17 +3,21 @@
|
|||
package html
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"codeberg.org/codeberg/pages/server/context"
|
||||
)
|
||||
|
||||
// ReturnErrorPage sets the response status code and writes NotFoundPage to the response body, with "%status" replaced
|
||||
// with the provided status code.
|
||||
func ReturnErrorPage(ctx *context.Context, code int) {
|
||||
func ReturnErrorPage(ctx *context.Context, msg string, code int) {
|
||||
ctx.RespWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
ctx.RespWriter.WriteHeader(code)
|
||||
|
||||
io.Copy(ctx.RespWriter, bytes.NewReader(errorBody(code)))
|
||||
if msg == "" {
|
||||
msg = errorBody(code)
|
||||
}
|
||||
|
||||
io.Copy(ctx.RespWriter, strings.NewReader(msg))
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ package html
|
|||
import _ "embed"
|
||||
|
||||
//go:embed 404.html
|
||||
var NotFoundPage []byte
|
||||
var NotFoundPage string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue