-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
79 lines (64 loc) · 2.06 KB
/
app.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"log"
"net/http"
"self-payrol/config"
"self-payrol/delivery"
"self-payrol/repository"
"self-payrol/usecase"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
type (
server struct {
httpServer *echo.Echo
cfg config.Config
}
Server interface {
Run()
}
)
func InitServer(cfg config.Config) Server {
e := echo.New()
e.HideBanner = true
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
return &server{
httpServer: e,
cfg: cfg,
}
}
func (s *server) Run() {
s.httpServer.GET("", func(e echo.Context) error {
return e.JSON(http.StatusOK, map[string]interface{}{
"status": "success",
"message": "Hello, World!" + s.cfg.ServiceName() + " " + s.cfg.ServiceEnvironment(),
})
})
positionRepo := repository.NewPositionRepository(s.cfg)
positionUsecase := usecase.NewPositionUsecase(positionRepo)
positionDelivery := delivery.NewPositionDelivery(positionUsecase)
positionGroup := s.httpServer.Group("/positions")
positionDelivery.Mount(positionGroup)
companyRepo := repository.NewCompanyRepository(s.cfg)
companyUsecase := usecase.NewCompanyUsecase(companyRepo)
companyDelivery := delivery.NewCompanyDelivery(companyUsecase)
companyGroup := s.httpServer.Group("/company")
companyDelivery.Mount(companyGroup)
// TODO: panggil user repository, user usecase, user derlivery, dan mount ke router
userRepo := repository.NewUserRepository(s.cfg)
userUsecase := usecase.NewUserUsecase(userRepo, positionRepo, companyRepo)
userDelivery := delivery.NewUserDelivery(userUsecase)
userGroup := s.httpServer.Group("/employee")
userDelivery.Mount(userGroup)
transactionRepo := repository.NewTransactionRepository(s.cfg)
transactionUsecase := usecase.NewTransactionUsecase(transactionRepo)
transactionDelivery := delivery.NewTransactionDelivery(transactionUsecase)
transactionGroup := s.httpServer.Group("/transactions")
transactionDelivery.Mount(transactionGroup)
if err := s.httpServer.Start(fmt.Sprintf(":%d", s.cfg.ServicePort())); err != nil {
log.Panic(err)
}
}