Refractor Codebase

This commit is contained in:
Phil 2023-04-05 22:29:43 +02:00
parent c98abe116e
commit a2d2d4c9f0
2 changed files with 18 additions and 33 deletions

View file

@ -11,33 +11,28 @@ import (
func ID(c *fiber.Ctx) error { func ID(c *fiber.Ctx) error {
val, err := db.Get(c.Params("id")) val, err := db.Get(c.Params("id"))
if c.Get("CLI") == "1" { if err != nil {
if err != nil { if c.Get("CLI") == "1" {
return c.Status(404).JSON(&fiber.Map{ return c.Status(404).JSON(&fiber.Map{
"error": true, "error": true,
"url": "URL not found", "url": "URL not found",
}) })
} else { } else {
_, err = db.StatsIncreaseViewsLinks() return c.Render("views/404", fiber.Map{
if err != nil { "BASEURL": utils.URL,
log.Fatal(err.Error())
}
return c.Status(301).JSON(&fiber.Map{
"error": false,
"url": val,
}) })
} }
} }
if err != nil {
return c.Render("views/404", fiber.Map{
"BASEURL": utils.URL,
})
}
_, err = db.StatsIncreaseViewsLinks() _, err = db.StatsIncreaseViewsLinks()
if err != nil { if err != nil {
log.Fatal(err.Error()) log.Fatal(err.Error())
} }
if c.Get("CLI") == "1" {
return c.Status(301).JSON(&fiber.Map{
"error": false,
"url": val,
})
}
return c.Redirect(val) return c.Redirect(val)
} }

View file

@ -14,27 +14,17 @@ var (
) )
func Init_build_vars() { func Init_build_vars() {
if CI_COMMIT_SHORT_SHA == "" && CI_COMMIT_BRANCH == "" { CI_BUILD = CI_COMMIT_SHORT_SHA != "" || CI_COMMIT_BRANCH != ""
CI_BUILD = false CI_TAGGED = CI_COMMIT_TAG != ""
} else {
CI_BUILD = true
}
if CI_COMMIT_TAG == "" {
CI_TAGGED = false
} else {
CI_TAGGED = true
}
} }
func Print_Starting_Screen() { func Print_Starting_Screen() {
if CI_BUILD { version := "unknown version"
if CI_TAGGED { if CI_TAGGED {
fmt.Println("---- Starting goshorly " + CI_COMMIT_TAG + " ----") version = CI_COMMIT_TAG
} else { } else if CI_BUILD {
fmt.Println("---- Starting goshorly " + CI_COMMIT_SHORT_SHA + " ----") version = CI_COMMIT_SHORT_SHA
}
} else {
fmt.Println("---- Starting goshorly " + "unknown version" + " ----")
} }
fmt.Println("---- Starting goshorly " + version + " ----")
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }