-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (66 loc) · 2.56 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"context"
"log"
"github.com/prometheus/client_golang/prometheus"
"github.com/rulanugrh/cressida/config"
"github.com/rulanugrh/cressida/internal/helper"
handler "github.com/rulanugrh/cressida/internal/http"
"github.com/rulanugrh/cressida/internal/repository"
"github.com/rulanugrh/cressida/internal/router"
"github.com/rulanugrh/cressida/internal/service"
)
// @version 1.1.0
// @title API Transporter with PostgreSQL
// @description Implement collect metric with prometheus and tracing with jaeger
// @BasePath /api/
// @host localhost:4000
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
// @security ApiKeyAuth
// @license.name MIT
// @license.url https://opensource.org/licenses/MIT
func main() {
// parsing connection opentelemetry
opentelemetry, err := helper.InitTracer()
if err != nil {
log.Fatalf("Error while trace provider: %v", err)
}
log.Println(err)
// defer function for checking opentelemetry while running and trace function
defer func(){
if err := opentelemetry.Shutdown(context.Background()); err != nil {
log.Fatalf("Error while trace provider: %v", err)
}
}()
// parsing connection for golang
mySQL := config.InitPostgreSQL()
db := mySQL.DatabaseConnection()
// running migration
config.Migration(db)
// running seeder
errs := config.Seeder(db)
log.Println(errs)
// connection for register
register := prometheus.NewRegistry()
// register for observability
observability := helper.NewPrometheus(register, nil)
// create new variabel for repository
userRepository := repository.NewUserRepository(mySQL)
orderRepository := repository.NewOrderRepository(mySQL)
vehicleRepository := repository.NewVehicleRepository(mySQL)
notificationRepository := repository.NewNotificationRepository(mySQL)
// create new variabel for service
userService := service.NewUserService(userRepository)
vehicleService := service.NewVehicleService(vehicleRepository)
notificationService := service.NewNotificationService(notificationRepository)
orderService := service.NewOrderService(orderRepository, vehicleRepository, notificationRepository)
// create new variabel for handler
userHandler := handler.NewUserHandler(userService, observability)
vehicleHandler := handler.NewVehicleHandler(vehicleService, observability)
orderHandler := handler.NewOrderHandler(orderService, observability)
notificationHandler := handler.NewNotificiationHandler(notificationService)
// parsing endpoint user
router.RouteEndpoint(userHandler, orderHandler, vehicleHandler, notificationHandler, register, observability)
}