-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.go
48 lines (41 loc) · 1.51 KB
/
render.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package webext
import "github.com/gofiber/fiber/v2"
// StatusError is an http status error
type StatusError struct {
status int
msg string
}
// NewStatusError returns a new status error
func NewStatusError(status int, msg string) *StatusError {
return &StatusError{status: status, msg: msg}
}
// Status returns the status error code
func (statusError *StatusError) Status() int {
return statusError.status
}
// Msg returns the status error message
func (statusError *StatusError) Msg() string {
return statusError.msg
}
// RenderPage is a method you can override.
//
// It is used to handle page rendering.
// You can decide how you want to handle pages here.
// You can also setup a templating engine of your choice with this method.
var RenderPage func(c *fiber.Ctx, url string, status int, args map[string]any) error = func(c *fiber.Ctx, url string, status int, args map[string]any) error {
//todo: handle page rendering
c.SendStatus(500)
return c.SendString("Render Page Handler Needs Setup")
}
// RenderError is a method you can override.
//
// It is used to handle http errors.
// You can decide how you want to handle rendering http errors here.
// You can also setup a templating engine of your choice with this method.
var RenderError func(c *fiber.Ctx, url string, statusError *StatusError, args map[string]any) error = func(c *fiber.Ctx, url string, statusError *StatusError, args map[string]any) error {
if statusError != nil {
c.SendStatus(statusError.status)
return c.SendString(statusError.msg)
}
return nil
}