2021-08-26 16:16:50 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strconv"
|
2021-09-08 16:56:03 +03:00
|
|
|
"time"
|
2021-08-26 16:16:50 +03:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2021-08-26 17:32:19 +03:00
|
|
|
_ "github.com/joho/godotenv/autoload"
|
2021-09-08 16:56:03 +03:00
|
|
|
limiter "github.com/ulule/limiter/v3"
|
|
|
|
mgin "github.com/ulule/limiter/v3/drivers/middleware/gin"
|
|
|
|
memory "github.com/ulule/limiter/v3/drivers/store/memory"
|
2021-08-26 16:16:50 +03:00
|
|
|
|
|
|
|
Config "micrach/config"
|
2021-08-26 20:23:55 +03:00
|
|
|
Controllers "micrach/controllers"
|
2021-09-03 02:34:45 +03:00
|
|
|
Db "micrach/db"
|
2021-08-30 12:09:27 +03:00
|
|
|
Repositories "micrach/repositories"
|
2021-09-04 21:53:48 +03:00
|
|
|
Utils "micrach/utils"
|
2021-08-26 16:16:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
Config.Init()
|
2021-09-03 02:34:45 +03:00
|
|
|
Db.Init()
|
|
|
|
defer Db.Pool.Close()
|
2021-08-26 16:16:50 +03:00
|
|
|
gin.SetMode(Config.App.Env)
|
2021-09-08 15:36:13 +03:00
|
|
|
if Config.App.SeedDb {
|
|
|
|
Repositories.Seed()
|
|
|
|
}
|
2021-08-26 16:16:50 +03:00
|
|
|
|
2021-09-04 21:53:48 +03:00
|
|
|
err := Utils.CreateUploadsFolder()
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
|
2021-09-08 16:56:03 +03:00
|
|
|
rate := limiter.Rate{
|
|
|
|
Period: 1 * time.Hour,
|
|
|
|
Limit: 1000,
|
|
|
|
}
|
|
|
|
store := memory.NewStore()
|
|
|
|
instance := limiter.New(store, rate)
|
|
|
|
middleware := mgin.NewMiddleware(instance)
|
|
|
|
|
2021-08-26 16:16:50 +03:00
|
|
|
router := gin.Default()
|
2021-08-28 17:34:58 +03:00
|
|
|
router.LoadHTMLGlob("templates/*.html")
|
2021-09-08 16:56:03 +03:00
|
|
|
router.ForwardedByClientIP = true
|
|
|
|
router.Use(middleware)
|
2021-08-28 18:41:34 +03:00
|
|
|
router.Static("/uploads", "./uploads")
|
2021-08-30 23:29:51 +03:00
|
|
|
router.Static("/static", "./static")
|
2021-08-26 20:23:55 +03:00
|
|
|
router.GET("/", Controllers.GetThreads)
|
|
|
|
router.POST("/", Controllers.CreateThread)
|
2021-09-05 00:36:55 +03:00
|
|
|
router.GET("/:threadID", Controllers.GetThread)
|
|
|
|
router.POST("/:threadID", Controllers.UpdateThread)
|
2021-08-26 16:16:50 +03:00
|
|
|
|
2021-08-28 19:30:14 +03:00
|
|
|
log.Println("port", Config.App.Port, "- online")
|
2021-08-26 16:16:50 +03:00
|
|
|
log.Println("all systems nominal")
|
|
|
|
|
2021-08-28 19:30:14 +03:00
|
|
|
router.Run(":" + strconv.Itoa(Config.App.Port))
|
2021-08-26 16:16:50 +03:00
|
|
|
}
|