2023-12-16 07:20:01 +00:00
|
|
|
package httpserver
|
|
|
|
|
2024-01-02 14:04:16 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-15 10:33:24 +00:00
|
|
|
|
|
|
|
config "git.gocasts.ir/ebhomengo/niki/config"
|
2024-01-22 08:14:57 +00:00
|
|
|
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
|
|
|
|
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
|
2024-01-22 14:41:55 +00:00
|
|
|
benefactoraddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/address"
|
2024-01-14 15:53:37 +00:00
|
|
|
benefactorhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/benefactor"
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/benefactor/kind_box_req"
|
2024-01-22 08:14:57 +00:00
|
|
|
adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin"
|
|
|
|
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
|
2024-01-25 11:43:39 +00:00
|
|
|
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
2024-01-17 20:17:06 +00:00
|
|
|
benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address"
|
2024-01-14 15:53:37 +00:00
|
|
|
benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor"
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req"
|
2024-01-22 08:14:57 +00:00
|
|
|
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
|
|
|
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
|
2024-01-22 14:41:55 +00:00
|
|
|
benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address"
|
2024-01-14 15:53:37 +00:00
|
|
|
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box_req"
|
2024-01-02 15:35:26 +00:00
|
|
|
echo "github.com/labstack/echo/v4"
|
|
|
|
middleware "github.com/labstack/echo/v4/middleware"
|
2024-01-02 14:04:16 +00:00
|
|
|
)
|
2023-12-16 07:20:01 +00:00
|
|
|
|
|
|
|
type Server struct {
|
2024-01-16 16:13:06 +00:00
|
|
|
config config.Config
|
|
|
|
Router *echo.Echo
|
|
|
|
benefactorHandler benefactorhandler.Handler
|
2024-01-17 20:17:06 +00:00
|
|
|
benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler
|
2024-01-22 14:41:55 +00:00
|
|
|
benefactorAddressHandler benefactoraddresshandler.Handler
|
2024-01-19 16:56:11 +00:00
|
|
|
adminHandler adminhandler.Handler
|
2024-01-22 08:14:57 +00:00
|
|
|
adminKindBoxReqHandler adminkindboxreqhandler.Handler
|
2023-12-16 07:20:01 +00:00
|
|
|
}
|
|
|
|
|
2024-01-16 16:13:06 +00:00
|
|
|
func New(
|
|
|
|
cfg config.Config,
|
|
|
|
benefactorSvc benefactorservice.Service,
|
|
|
|
benefactorVld benefactorvalidator.Validator,
|
2024-01-25 11:43:39 +00:00
|
|
|
benefactorAuthSvc authservice.Service,
|
2024-01-16 16:13:06 +00:00
|
|
|
benefactorKindBoxReqSvc benefactorkindboxreqservice.Service,
|
|
|
|
benefactorKindBoxReqVld benefactorkindboxreqvalidator.Validator,
|
2024-01-17 20:17:06 +00:00
|
|
|
benefactorAddressSvc benefactoraddressservice.Service,
|
2024-01-22 14:41:55 +00:00
|
|
|
benefactorAddressVld benefactoraddressvalidator.Validator,
|
2024-01-19 16:56:11 +00:00
|
|
|
adminSvc adminservice.Service,
|
|
|
|
adminVld adminvalidator.Validator,
|
2024-01-25 11:43:39 +00:00
|
|
|
adminAuthSvc authservice.Service,
|
2024-01-22 08:14:57 +00:00
|
|
|
adminKinBoxReqSvc adminkindboxreqservice.Service,
|
|
|
|
adminKinBoxReqVld adminkindboxreqvalidator.Validator,
|
2024-01-16 16:13:06 +00:00
|
|
|
) Server {
|
2023-12-16 07:20:01 +00:00
|
|
|
return Server{
|
2024-01-16 16:13:06 +00:00
|
|
|
Router: echo.New(),
|
|
|
|
config: cfg,
|
2024-01-25 11:43:39 +00:00
|
|
|
benefactorHandler: benefactorhandler.New(cfg.Auth, benefactorAuthSvc, benefactorSvc, benefactorVld),
|
|
|
|
benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(cfg.Auth, benefactorAuthSvc, benefactorKindBoxReqSvc, benefactorKindBoxReqVld),
|
|
|
|
benefactorAddressHandler: benefactoraddresshandler.New(cfg.Auth, benefactorAuthSvc, benefactorAddressSvc, benefactorAddressVld),
|
2024-01-19 16:56:11 +00:00
|
|
|
adminHandler: adminhandler.New(cfg.AdminAuth, adminAuthSvc, adminSvc, adminVld),
|
2024-01-26 06:17:38 +00:00
|
|
|
adminKindBoxReqHandler: adminkindboxreqhandler.New(cfg.Auth, adminAuthSvc, adminKinBoxReqSvc, adminKinBoxReqVld),
|
2023-12-16 07:20:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Server) Serve() {
|
2024-01-02 14:04:16 +00:00
|
|
|
s.Router.Use(middleware.RequestID())
|
|
|
|
|
|
|
|
s.Router.Use(middleware.Recover())
|
|
|
|
|
|
|
|
// Routes
|
|
|
|
s.Router.GET("/health-check", s.healthCheck)
|
2024-01-14 15:53:37 +00:00
|
|
|
s.benefactorHandler.SetRoutes(s.Router)
|
2024-01-17 20:17:06 +00:00
|
|
|
s.benefactorKindBoxReqHandler.SetRoutes(s.Router)
|
2024-01-22 14:41:55 +00:00
|
|
|
s.benefactorAddressHandler.SetRoutes(s.Router)
|
2024-01-19 16:56:11 +00:00
|
|
|
s.adminHandler.SetRoutes(s.Router)
|
2024-01-22 08:14:57 +00:00
|
|
|
s.adminKindBoxReqHandler.SetRoutes(s.Router)
|
2024-01-02 14:04:16 +00:00
|
|
|
|
|
|
|
// Start server
|
|
|
|
address := fmt.Sprintf(":%d", s.config.HTTPServer.Port)
|
|
|
|
fmt.Printf("start echo server on %s\n", address)
|
|
|
|
if err := s.Router.Start(address); err != nil {
|
|
|
|
fmt.Println("router start error", err)
|
|
|
|
}
|
2023-12-20 15:39:25 +00:00
|
|
|
}
|