- Add bootstrap package to initialize application components including logger, tracer, and HTTP server. - Create config package to load runtime settings from environment variables. - Implement observability features including logging, metrics, and tracing. - Add health check and hello use cases with corresponding HTTP handlers. - Introduce middleware for request ID, access logging, metrics, and recovery. - Set up HTTP router with defined routes for health and hello endpoints. - Include tests for health and hello endpoints to ensure proper functionality. - Add OpenTelemetry collector configuration for trace exporting.
32 lines
740 B
Go
32 lines
740 B
Go
package health
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// Checker allows plugging external dependency checks into readiness.
|
|
type Checker interface {
|
|
Name() string
|
|
Check(ctx context.Context) error
|
|
}
|
|
|
|
// ReadinessUsecase executes dependency checks used by /readyz.
|
|
type ReadinessUsecase struct {
|
|
checkers []Checker
|
|
}
|
|
|
|
func NewReadinessUsecase(checkers []Checker) *ReadinessUsecase {
|
|
return &ReadinessUsecase{checkers: checkers}
|
|
}
|
|
|
|
func (u *ReadinessUsecase) Check(ctx context.Context) error {
|
|
// TODO: add concrete dependency checkers (DB, cache, third-party APIs) as needed.
|
|
for _, checker := range u.checkers {
|
|
if err := checker.Check(ctx); err != nil {
|
|
return fmt.Errorf("%s check failed: %w", checker.Name(), err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|