micrach/main.go
Yanislav Igonin 242abb8645
Feature - Migrator (#3)
* feat: rename init migration

* feat: add migration for is_archived field

* fix: thread title wrap

* fix: captcha checks after post validation now

* fix

* wip on migrate method

* feat: decided to write own migrator

* feat: add get files on folder func

* wip

* feat: add migrations table

* feat: add migration method

* doc

* feat: query -> exec
2021-11-17 11:44:12 +03:00

76 lines
1.7 KiB
Go

package main
import (
"html/template"
"log"
"strconv"
"time"
"github.com/gin-gonic/gin"
_ "github.com/joho/godotenv/autoload"
limiter "github.com/ulule/limiter/v3"
mgin "github.com/ulule/limiter/v3/drivers/middleware/gin"
memory "github.com/ulule/limiter/v3/drivers/store/memory"
Config "micrach/config"
Controllers "micrach/controllers"
Db "micrach/db"
Repositories "micrach/repositories"
Utils "micrach/utils"
)
func main() {
Config.Init()
Db.Init()
Db.Migrate()
defer Db.Pool.Close()
gin.SetMode(Config.App.Env)
if Config.App.SeedDb {
Repositories.Seed()
}
err := Utils.CreateUploadsFolder()
if err != nil {
log.Panicln(err)
}
rate := limiter.Rate{
Period: 1 * time.Hour,
Limit: 1000,
}
rateLimiterStore := memory.NewStore()
instance := limiter.New(rateLimiterStore, rate)
middleware := mgin.NewMiddleware(instance)
router := gin.New()
router.Use(gin.Recovery())
router.SetFuncMap(template.FuncMap{
"Iterate": func(count int) []int {
var i int
var Items []int
for i = 1; i < count+1; i++ {
Items = append(Items, i)
}
return Items
},
})
router.LoadHTMLGlob("templates/*.html")
router.ForwardedByClientIP = true
if Config.App.IsRateLimiterEnabled {
router.Use(middleware)
}
router.Static("/uploads", "./uploads")
router.Static("/static", "./static")
router.GET("/", Controllers.GetThreads)
router.POST("/", Controllers.CreateThread)
router.GET("/:threadID", Controllers.GetThread)
router.POST("/:threadID", Controllers.UpdateThread)
router.GET("/captcha/:captchaID", Controllers.GetCaptcha)
log.Println("port", Config.App.Port, "- online")
log.Println("all systems nominal")
router.Run(":" + strconv.Itoa(Config.App.Port))
}