goshorly/main.go

48 lines
853 B
Go
Raw Normal View History

2021-12-07 14:49:58 +00:00
package main
import (
2021-12-07 18:10:53 +00:00
"embed"
2021-12-07 14:49:58 +00:00
"log"
"net/http"
2023-09-04 18:59:51 +00:00
"git.hackmi.ch/Phil/goshorly/db"
"git.hackmi.ch/Phil/goshorly/routes"
"git.hackmi.ch/Phil/goshorly/utils"
2021-12-07 14:49:58 +00:00
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/limiter"
2024-04-19 14:54:09 +00:00
"github.com/gofiber/template/html/v2"
2021-12-07 14:49:58 +00:00
)
2021-12-07 18:13:06 +00:00
//go:embed views/*
var viewsfs embed.FS
2021-12-07 18:10:53 +00:00
2021-12-07 18:13:06 +00:00
func main() {
2022-01-25 16:25:23 +00:00
utils.Print_Starting_Screen()
2022-03-24 08:08:12 +00:00
utils.Init_env_file()
2021-12-08 10:04:28 +00:00
utils.Init_env_vars()
utils.Init_build_vars()
db.Init_redis()
2021-12-07 18:10:53 +00:00
engine := html.NewFileSystem(http.FS(viewsfs), ".html")
2021-12-07 14:49:58 +00:00
app := fiber.New(fiber.Config{
2021-12-07 18:10:53 +00:00
CaseSensitive: true,
Views: engine,
2021-12-07 14:49:58 +00:00
})
app.Get("/", routes.Gethome)
2021-12-07 14:49:58 +00:00
if utils.ESTATS == "true" {
app.Get("/stats", routes.GetStats)
}
app.Get("/:id", routes.ID)
2021-12-07 14:49:58 +00:00
app.Use(limiter.New(utils.ConfigLimiter))
2021-12-07 14:49:58 +00:00
app.Post("/", routes.Posthome)
2021-12-07 14:49:58 +00:00
2021-12-07 19:23:27 +00:00
log.Fatal(app.Listen(":" + utils.PORT))
2021-12-07 14:49:58 +00:00
}