summaryrefslogtreecommitdiff
path: root/utils/shortcuts/redirect.go
blob: 1add12fb4a4501849f48b1258458ca745fd28c41 (plain)
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
package shortcuts

import (
	"lain/utils/urls"

	"github.com/gofiber/fiber/v2"
)

func Redirect(ctx *fiber.Ctx, routeName string) error {
	path, ok := urls.GetFullPath(routeName)
	if !ok {
		return fiber.ErrNotFound
	}
	return ctx.Redirect(path)
}

func RedirectWithStatus(ctx *fiber.Ctx, routeName string, statusCode int) error {
	path, ok := urls.GetFullPath(routeName)
	if !ok {
		return fiber.ErrNotFound
	}
	return ctx.Redirect(path, statusCode)
}

func RedirectTo(route string) fiber.Handler {
	return func(ctx *fiber.Ctx) error {
		return Redirect(ctx, route)
	}
}

func RedirectWithFlash(context *fiber.Ctx, routeName string, data fiber.Map) error {
	if err := Flash(context, data); err != nil {
		return err
	}
	return Redirect(context, routeName)
}