-
Notifications
You must be signed in to change notification settings - Fork 1
/
health_check_usecase.go
58 lines (49 loc) · 1.67 KB
/
health_check_usecase.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
package healthCheckUseCase
import (
healthCheckDomain "github.com/infranyx/go-microservice-template/internal/health_check/domain"
healthCheckDto "github.com/infranyx/go-microservice-template/internal/health_check/dto"
)
type useCase struct {
postgresHealthCheckUc healthCheckDomain.PostgresHealthCheckUseCase
kafkaHealthCheckUc healthCheckDomain.KafkaHealthCheckUseCase
tmpDirHealthCheckUc healthCheckDomain.TmpDirHealthCheckUseCase
}
func NewUseCase(
postgresHealthCheckUc healthCheckDomain.PostgresHealthCheckUseCase,
kafkaHealthCheckUc healthCheckDomain.KafkaHealthCheckUseCase,
tmpDirHealthCheckUc healthCheckDomain.TmpDirHealthCheckUseCase,
) healthCheckDomain.HealthCheckUseCase {
return &useCase{
postgresHealthCheckUc: postgresHealthCheckUc,
kafkaHealthCheckUc: kafkaHealthCheckUc,
tmpDirHealthCheckUc: tmpDirHealthCheckUc,
}
}
func (uc *useCase) Check() *healthCheckDto.HealthCheckResponseDto {
healthCheckResult := healthCheckDto.HealthCheckResponseDto{
Status: true,
Units: nil,
}
pgUnit := healthCheckDto.HealthCheckUnit{
Unit: "postgres",
Up: uc.postgresHealthCheckUc.Check(),
}
healthCheckResult.Units = append(healthCheckResult.Units, pgUnit)
kafkaUnit := healthCheckDto.HealthCheckUnit{
Unit: "kafka",
Up: uc.kafkaHealthCheckUc.Check(),
}
healthCheckResult.Units = append(healthCheckResult.Units, kafkaUnit)
tmpDirUnit := healthCheckDto.HealthCheckUnit{
Unit: "writable-tmp-dir",
Up: uc.tmpDirHealthCheckUc.Check(),
}
healthCheckResult.Units = append(healthCheckResult.Units, tmpDirUnit)
for _, v := range healthCheckResult.Units {
if !v.Up {
healthCheckResult.Status = false
break
}
}
return &healthCheckResult
}