From 52a0248c1c81a14699b3d33ba7efe0c56bbe7477 Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 7 Jul 2025 22:57:31 +0530 Subject: massive y2k retro overhaul with sidebar, context processors, and proper database organization --- processors/request.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 processors/request.go (limited to 'processors/request.go') 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() +} -- cgit v1.2.3