goshorly/routes/id.go
2021-12-10 22:38:02 +01:00

32 lines
579 B
Go

package routes
import (
"git.ucode.space/Phil/goshorly/db"
"git.ucode.space/Phil/goshorly/utils"
"github.com/gofiber/fiber/v2"
)
func ID(c *fiber.Ctx) error {
val, err := db.Client.Get(c.Params("id")).Result()
if c.Get("CLI") == "1" {
if err != nil {
return c.Status(404).JSON(&fiber.Map{
"error": true,
"url": "URL not found",
})
} else {
return c.Status(301).JSON(&fiber.Map{
"error": false,
"url": val,
})
}
}
if err != nil {
return c.Render("views/404", fiber.Map{
"BASEURL": utils.URL,
})
}
return c.Redirect(val)
}