aboutsummaryrefslogtreecommitdiff
path: root/processors/request.go
diff options
context:
space:
mode:
Diffstat (limited to 'processors/request.go')
-rw-r--r--processors/request.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/processors/request.go b/processors/request.go
new file mode 100644
index 0000000..f4fe8d2
--- /dev/null
+++ b/processors/request.go
@@ -0,0 +1,45 @@
+package processors
+
+import (
+ "github.com/gofiber/fiber/v2"
+)
+
+type QueryParam struct {
+ Key string
+ Value string
+}
+
+type Request struct {
+ Path string
+ Method string
+ Query []QueryParam
+ Params []QueryParam
+ QueryString string
+ IP string
+ URL string
+}
+
+func RequestContextProcessor(ctx *fiber.Ctx) error {
+ queryParams := []QueryParam{}
+ for k, v := range ctx.Queries() {
+ queryParams = append(queryParams, QueryParam{Key: k, Value: v})
+ }
+
+ routeParams := []QueryParam{}
+ for k, v := range ctx.AllParams() {
+ routeParams = append(routeParams, QueryParam{Key: k, Value: v})
+ }
+
+ request := Request{
+ Path: ctx.Path(),
+ Method: ctx.Method(),
+ Query: queryParams,
+ Params: routeParams,
+ QueryString: string(ctx.Request().URI().QueryString()),
+ IP: ctx.IP(),
+ URL: ctx.OriginalURL(),
+ }
+
+ ctx.Locals("Request", request)
+ return ctx.Next()
+}