Initial commit.
This commit is contained in:
commit
63f43e568c
23 changed files with 1199 additions and 0 deletions
56
router/router.go
Normal file
56
router/router.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/labstack/echo-contrib/session"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
||||
"goweb/container"
|
||||
"goweb/controllers"
|
||||
)
|
||||
|
||||
const StaticDir = "static"
|
||||
|
||||
func BuildRouter(c *container.Container) {
|
||||
// Middleware
|
||||
c.Web.Use(middleware.RemoveTrailingSlashWithConfig(middleware.TrailingSlashConfig{
|
||||
RedirectCode: http.StatusMovedPermanently,
|
||||
}))
|
||||
c.Web.Use(middleware.RequestID())
|
||||
c.Web.Use(middleware.Recover())
|
||||
c.Web.Use(middleware.Gzip())
|
||||
c.Web.Use(middleware.Logger())
|
||||
// TODO: needs cache control headers
|
||||
c.Web.Use(middleware.Static(StaticDir))
|
||||
c.Web.Use(session.Middleware(sessions.NewCookieStore([]byte(c.Config.App.EncryptionKey))))
|
||||
|
||||
// Base controller
|
||||
ctr := controllers.NewController(c)
|
||||
|
||||
// Error handler
|
||||
err := controllers.Error{Controller: ctr}
|
||||
c.Web.HTTPErrorHandler = err.Get
|
||||
|
||||
// Routes
|
||||
navRoutes(c.Web, ctr)
|
||||
userRoutes(c.Web, ctr)
|
||||
}
|
||||
|
||||
func navRoutes(e *echo.Echo, ctr controllers.Controller) {
|
||||
home := controllers.Home{Controller: ctr}
|
||||
e.GET("/", home.Get).Name = "home"
|
||||
|
||||
about := controllers.About{Controller: ctr}
|
||||
e.GET("/about", about.Get).Name = "about"
|
||||
|
||||
contact := controllers.Contact{Controller: ctr}
|
||||
e.GET("/contact", contact.Get).Name = "contact"
|
||||
e.POST("/contact", contact.Post).Name = "contact.post"
|
||||
}
|
||||
|
||||
func userRoutes(e *echo.Echo, ctr controllers.Controller) {
|
||||
// TODO
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue