-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (52 loc) · 2.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"foodmarket/config"
"foodmarket/db/postgre"
"net/http"
"time"
_foodHttpDelivery "foodmarket/food/delivery/http"
_foodPostgreRepository "foodmarket/food/repository/postgre"
_foodUseCase "foodmarket/food/usecase"
_orderHttpDelivery "foodmarket/order/delivery/http"
_orderPostgreRepository "foodmarket/order/repository/postgre"
_orderUseCase "foodmarket/order/usecase"
_userHttDelivery "foodmarket/user/delivery/http"
_userPostgreRepository "foodmarket/user/repository/postgre"
_userUseCase "foodmarket/user/usecase"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/spf13/viper"
)
func main() {
config.Read()
dbConnector := postgre.Connect()
timeoutCtx := time.Duration(5) * time.Second
server := &http.Server{
Addr: ":" + viper.GetString("app_port"),
ReadTimeout: 20 * time.Minute,
WriteTimeout: 20 * time.Minute,
}
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Welcome to "+viper.GetString("app_name"))
})
orderRepo := _orderPostgreRepository.NewPsqlOrderRepository(dbConnector)
userRepo := _userPostgreRepository.NewPsqlUserRepository(dbConnector)
foodRepo := _foodPostgreRepository.NewPostgreFoodRepository(dbConnector)
orderUsecase := _orderUseCase.NewOrderUsecase(orderRepo, foodRepo, timeoutCtx)
foodUsecase := _foodUseCase.NewFoodUsecase(foodRepo, timeoutCtx)
userUsecase := _userUseCase.NewUserUsecase(userRepo, timeoutCtx)
_orderHttpDelivery.NewOrderHandler(e, orderUsecase)
_foodHttpDelivery.NewFoodHandler(e, foodUsecase)
_userHttDelivery.NewUserHandler(e, userUsecase)
err := e.StartServer(server)
if err != nil {
e.Logger.Info("Shutting down the server")
}
}