diff options
| author | Bobby <[email protected]> | 2025-12-19 18:01:24 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-12-19 18:01:24 +0530 |
| commit | b1bfec1ce2987d9fe0cc52e5ae9115977fdf8c24 (patch) | |
| tree | 7080b7dc97522ffe0837a1e0b2965489d7e67664 /utils/meta | |
| parent | 767297e28d47ee9cf3722054e41caa837f0e68d2 (diff) | |
| download | lain-b1bfec1ce2987d9fe0cc52e5ae9115977fdf8c24.tar.xz lain-b1bfec1ce2987d9fe0cc52e5ae9115977fdf8c24.zip | |
added utils, templates, routes, types, middleware, processors and a whole lot of things for a basic login page
Diffstat (limited to 'utils/meta')
| -rw-r--r-- | utils/meta/request.go | 47 | ||||
| -rw-r--r-- | utils/meta/title.go | 13 |
2 files changed, 60 insertions, 0 deletions
diff --git a/utils/meta/request.go b/utils/meta/request.go new file mode 100644 index 0000000..e1db77c --- /dev/null +++ b/utils/meta/request.go @@ -0,0 +1,47 @@ +package meta + +import ( + "lain/types" + + "github.com/gofiber/fiber/v2" +) + +func BuildRequest(context *fiber.Ctx) types.HTTPRequest { + return types.HTTPRequest{ + Path: context.Path(), + Method: context.Method(), + Query: buildQueryParams(context), + Params: buildRouteParams(context), + QueryString: string(context.Request().URI().QueryString()), + IP: context.IP(), + URL: context.OriginalURL(), + } +} + +func buildQueryParams(context *fiber.Ctx) []types.HTTPQueryParam { + params := make([]types.HTTPQueryParam, 0) + args := context.Request().URI().QueryArgs() + + args.VisitAll(transformQueryParam(¶ms)) + return params +} + +func buildRouteParams(context *fiber.Ctx) []types.HTTPQueryParam { + params := make([]types.HTTPQueryParam, 0) + for key, value := range context.AllParams() { + params = append(params, types.HTTPQueryParam{ + Key: key, + Value: value, + }) + } + return params +} + +func transformQueryParam(params *[]types.HTTPQueryParam) func(key, value []byte) { + return func(key, value []byte) { + *params = append(*params, types.HTTPQueryParam{ + Key: string(key), + Value: string(value), + }) + } +} diff --git a/utils/meta/title.go b/utils/meta/title.go new file mode 100644 index 0000000..27ee2ed --- /dev/null +++ b/utils/meta/title.go @@ -0,0 +1,13 @@ +package meta + +import ( + "fmt" + "lain/config" + + "github.com/gofiber/fiber/v2" +) + +func SetPageTitle(context *fiber.Ctx, title string) { + title = fmt.Sprintf("%s | %s", title, config.Server.AppName) + context.Locals("Title", title) +} |
