mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
79e6cc8e5b
* feat: add geateway config * feat: add ping controller for check by gateway * feat: add new env vars for gateway * feat: update config * gateway request wip * feat: add auth header for gateway request * feat: separate gateway folder * update endpoint for gateway * add makefile * lint * swap png to svg * add url of board to request to gateway * change deployed path prefix * add env in compose * add body log on gateway connect
81 lines
1.8 KiB
Go
81 lines
1.8 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"
|
|
|
|
Build "micrach/build"
|
|
Config "micrach/config"
|
|
Controllers "micrach/controllers"
|
|
Db "micrach/db"
|
|
Gateway "micrach/gateway"
|
|
Repositories "micrach/repositories"
|
|
Templates "micrach/templates"
|
|
Utils "micrach/utils"
|
|
)
|
|
|
|
func main() {
|
|
Config.Init()
|
|
Db.Init()
|
|
Db.Migrate()
|
|
defer Db.Pool.Close()
|
|
gin.SetMode(Config.App.Env)
|
|
if Config.App.IsDbSeeded {
|
|
Repositories.Seed()
|
|
}
|
|
|
|
if Config.App.Env == "release" {
|
|
Build.RenameCss()
|
|
}
|
|
|
|
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": Templates.Iterate,
|
|
"NotNil": Templates.NotNil,
|
|
})
|
|
router.LoadHTMLGlob("templates/**/*")
|
|
router.ForwardedByClientIP = true
|
|
if Config.App.IsRateLimiterEnabled {
|
|
router.Use(middleware)
|
|
}
|
|
router.Static("/uploads", "./uploads")
|
|
router.Static("/static", "./static")
|
|
if Config.App.Gateway.Url != "" {
|
|
router.GET("/api/ping", Gateway.Ping)
|
|
Gateway.Connect()
|
|
}
|
|
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))
|
|
}
|