2021-08-26 16:16:50 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-04-06 00:30:36 +03:00
|
|
|
"log"
|
2022-04-06 10:59:05 +03:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
_ "github.com/joho/godotenv/autoload"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2022-04-06 12:35:42 +03:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/compress"
|
2022-04-06 12:44:55 +03:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/etag"
|
2022-04-06 10:59:05 +03:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/limiter"
|
2022-04-06 13:08:09 +03:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/recover"
|
2022-04-06 10:59:05 +03:00
|
|
|
"github.com/gofiber/template/html"
|
|
|
|
|
2022-04-06 00:30:36 +03:00
|
|
|
"micrach/build"
|
|
|
|
"micrach/config"
|
2022-04-06 11:45:39 +03:00
|
|
|
"micrach/controllers"
|
2022-04-06 00:30:36 +03:00
|
|
|
"micrach/db"
|
|
|
|
"micrach/repositories"
|
2022-04-06 01:08:53 +03:00
|
|
|
"micrach/templates"
|
2022-04-06 00:30:36 +03:00
|
|
|
"micrach/utils"
|
2021-08-26 16:16:50 +03:00
|
|
|
)
|
|
|
|
|
2022-04-06 00:16:22 +03:00
|
|
|
// func main() {
|
|
|
|
// if Config.App.IsRateLimiterEnabled {
|
|
|
|
// router.Use(middleware)
|
|
|
|
// }
|
|
|
|
// if Config.App.Gateway.Url != "" {
|
|
|
|
// router.GET("/api/ping", Gateway.Ping)
|
|
|
|
// Gateway.Connect()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
func main() {
|
2022-04-06 00:30:36 +03:00
|
|
|
config.Init()
|
|
|
|
db.Init()
|
|
|
|
db.Migrate()
|
|
|
|
defer db.Pool.Close()
|
|
|
|
|
|
|
|
if config.App.IsDbSeeded {
|
|
|
|
repositories.Seed()
|
|
|
|
}
|
|
|
|
|
2022-04-06 00:35:29 +03:00
|
|
|
if config.App.Env == "production" {
|
2022-04-06 00:30:36 +03:00
|
|
|
build.RenameCss()
|
|
|
|
}
|
|
|
|
|
|
|
|
err := utils.CreateUploadsFolder()
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
|
2022-04-06 01:08:53 +03:00
|
|
|
engine := html.New("./templates", ".html")
|
|
|
|
engine.AddFunc("Iterate", templates.Iterate)
|
|
|
|
engine.AddFunc("NotNil", templates.NotNil)
|
2022-04-06 12:52:34 +03:00
|
|
|
|
|
|
|
app := fiber.New(fiber.Config{Views: engine})
|
|
|
|
|
2022-04-06 13:08:09 +03:00
|
|
|
app.Use(recover.New())
|
2022-04-06 10:59:05 +03:00
|
|
|
app.Use(limiter.New(limiter.Config{
|
2022-04-06 13:35:53 +03:00
|
|
|
Next: func(c *fiber.Ctx) bool { return c.IsFromLocal() },
|
2022-04-06 10:59:05 +03:00
|
|
|
}))
|
2022-04-06 12:35:42 +03:00
|
|
|
app.Use(compress.New())
|
2022-04-06 12:44:55 +03:00
|
|
|
app.Use(etag.New())
|
2022-04-06 12:52:34 +03:00
|
|
|
|
2022-04-06 00:43:37 +03:00
|
|
|
app.Static("/uploads", "./uploads")
|
|
|
|
app.Static("/static", "./static")
|
2022-04-06 00:16:22 +03:00
|
|
|
|
2022-04-06 11:45:39 +03:00
|
|
|
app.Get("/", controllers.GetThreads)
|
2022-04-06 00:43:13 +03:00
|
|
|
app.Post("/", func(c *fiber.Ctx) error {
|
|
|
|
return c.SendString("create thread")
|
|
|
|
})
|
|
|
|
app.Get("/:threadID", func(c *fiber.Ctx) error {
|
|
|
|
return c.SendString("get thread by id")
|
|
|
|
})
|
|
|
|
app.Post("/threadID", func(c *fiber.Ctx) error {
|
|
|
|
return c.SendString("create post in thread")
|
|
|
|
})
|
|
|
|
app.Get("/captcha/:captchaID", func(c *fiber.Ctx) error {
|
|
|
|
return c.SendString("get captcha by id")
|
2022-04-06 00:16:22 +03:00
|
|
|
})
|
2021-08-26 16:16:50 +03:00
|
|
|
|
2022-04-06 00:30:36 +03:00
|
|
|
log.Println("app - online, port -", strconv.Itoa(config.App.Port))
|
|
|
|
log.Println("all systems nominal")
|
|
|
|
err = app.Listen(":" + strconv.Itoa(config.App.Port))
|
|
|
|
if err != nil {
|
|
|
|
log.Println("app - ofline")
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
2021-08-26 16:16:50 +03:00
|
|
|
}
|