more robust controller
This commit is contained in:
parent
48e041a929
commit
2aa7f9bebf
@ -1,7 +1,13 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/gob"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/flosch/pongo2/v4"
|
||||||
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.uber.org/ratelimit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() *gin.Engine {
|
func Init() *gin.Engine {
|
||||||
@ -11,11 +17,26 @@ func Init() *gin.Engine {
|
|||||||
app.Use(gin.Logger())
|
app.Use(gin.Logger())
|
||||||
app.Use(gin.Recovery())
|
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
|
// static files
|
||||||
app.Static("/public", "./public")
|
app.Static("/public", "./public")
|
||||||
|
|
||||||
// HTML templates
|
// HTML templates
|
||||||
app.HTMLRender = templatePath("views")
|
app.HTMLRender = templatePath("views")
|
||||||
|
|
||||||
|
// register gob
|
||||||
|
gob.Register(pongo2.Context{})
|
||||||
|
gob.Register(time.Time{})
|
||||||
|
|
||||||
|
// routes
|
||||||
|
templateDataGroup := app.Group("/", templateDataMiddleware)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user