pink_fox/application/inner/registration_routes.go

58 lines
1.3 KiB
Go

package inner
import (
"pink_fox/inner/controllers"
"pink_fox/inner/di"
"pink_fox/inner/middlewares"
"pink_fox/inner/storage"
"pink_fox/packages/fw"
)
func RegistrationRoutes(rm *fw.RouterManager[*storage.Storage, *di.Container]) {
rm.Use(errorMiddleware, responseMiddleware)
rm.NotFound(noRoute2)
rm.Get("/ping", ping)
rm.Get("/", siteIndex)
api := rm.Group("/api")
{
api.NotFound(noRouteApi)
api.Get("/ping", ping)
sub := api.Group("/sub")
{
sub.NotFound(noRouteBack)
sub.Get("/ping", ping)
}
}
}
func siteIndex(di *di.Container) (fw.Response, fw.Error) {
return controllers.NewSiteController(di).Index()
}
func ping(di *di.Container) (fw.Response, fw.Error) {
return controllers.NewPingController(di).Index()
}
func errorMiddleware(di *di.Container, next fw.ActionFunc) (fw.Response, fw.Error) {
return middlewares.ErrorMiddleware(di, next)
}
func responseMiddleware(_ *di.Container, next fw.ActionFunc) (fw.Response, fw.Error) {
return middlewares.ResponseMiddleware(next)
}
func noRoute2(di *di.Container) (fw.Response, fw.Error) {
return controllers.NewHttpErrorController(di).Page404()
}
func noRouteApi(di *di.Container) (fw.Response, fw.Error) {
return controllers.NewHttpErrorController(di).Api404()
}
func noRouteBack(di *di.Container) (fw.Response, fw.Error) {
return controllers.NewHttpErrorController(di).Back404()
}