experiment: successfully implemented dependency injections for controllers and services
This commit is contained in:
@@ -6,10 +6,18 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type HealthStatus struct {
|
||||
Healthy bool `json:"healthy"`
|
||||
type ServiceController interface {
|
||||
HealthCheck(c *gin.Context)
|
||||
Router
|
||||
}
|
||||
|
||||
type serviceControllerImpl struct{}
|
||||
|
||||
func NewServiceController() ServiceController {
|
||||
return &serviceControllerImpl{}
|
||||
}
|
||||
|
||||
// HealthCheck implements ServiceController.
|
||||
// @Summary Get health status
|
||||
// @Description Used internally for checking service health
|
||||
// @Tags Service
|
||||
@@ -17,6 +25,15 @@ type HealthStatus struct {
|
||||
// @Produce json
|
||||
// @Success 200 {object} HealthStatus "Says whether it's healthy or not"
|
||||
// @Router /service/health [get]
|
||||
func HealthCheck(c *gin.Context) {
|
||||
func (s *serviceControllerImpl) HealthCheck(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"healthy": true})
|
||||
}
|
||||
|
||||
// RegisterRoutes implements ServiceController.
|
||||
func (s *serviceControllerImpl) RegisterRoutes(group *gin.RouterGroup) {
|
||||
group.GET("/health", s.HealthCheck)
|
||||
}
|
||||
|
||||
type HealthStatus struct {
|
||||
Healthy bool `json:"healthy"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user