-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiber.go
48 lines (37 loc) · 896 Bytes
/
fiber.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 querybind
import (
"net/url"
"github.com/gofiber/fiber/v2"
)
type fiberContext struct {
*fiber.Ctx
}
func Fiber(ctx *fiber.Ctx) fiberContext {
return fiberContext{
Ctx: ctx,
}
}
func (f fiberContext) GetHeader(name string) string {
return f.Ctx.Get(name)
}
func (f fiberContext) SetHeader(name, value string) {
f.Ctx.Set("HX-Push-Url", value)
}
func (f fiberContext) QueryParams(params *url.Values) {
// Combine with the current HTMX request's query parameters
f.Ctx.Context().QueryArgs().VisitAll(func(key, value []byte) {
params.Set(string(key), string(value))
})
}
func (f fiberContext) OriginalURL() string {
return string(f.Ctx.Request().Header.Referer())
}
func (f fiberContext) Referer() string {
return f.Ctx.OriginalURL()
}
func (f fiberContext) BaseUrl() string {
return f.Ctx.BaseURL()
}
func (f fiberContext) Path() string {
return f.Ctx.Path()
}