43 lines
802 B
Go
43 lines
802 B
Go
package controller
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"time"
|
|
|
|
"github.com/flosch/pongo2/v4"
|
|
"github.com/gin-contrib/cors"
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/ratelimit"
|
|
)
|
|
|
|
func Init() *gin.Engine {
|
|
gin.SetMode(gin.DebugMode)
|
|
|
|
app := gin.New()
|
|
app.Use(gin.Logger())
|
|
app.Use(gin.Recovery())
|
|
|
|
// op-sec stuff
|
|
rl = ratelimit.New(100) // 100 req/s
|
|
app.Use(cors.New(cors.Config{AllowOrigins: []string{"http://localhost", "http://127.0.0.1"}}))
|
|
app.Use(rateLimitMiddleware)
|
|
|
|
// static files
|
|
app.Static("/public", "./public")
|
|
|
|
// HTML templates
|
|
app.HTMLRender = templatePath("views")
|
|
|
|
// register gob
|
|
gob.Register(pongo2.Context{})
|
|
gob.Register(time.Time{})
|
|
|
|
// routes
|
|
templateDataGroup := app.Group("/", templateDataMiddleware)
|
|
{
|
|
templateDataGroup.GET("/", indexHandler)
|
|
}
|
|
|
|
return app
|
|
}
|