31 lines
555 B
Go
31 lines
555 B
Go
// Package health provides the service readiness use case.
|
|
package health
|
|
|
|
import "context"
|
|
|
|
type Database interface {
|
|
Ping(context.Context) error
|
|
}
|
|
|
|
type Status struct {
|
|
Serving bool
|
|
DatabaseReady bool
|
|
}
|
|
|
|
type Service struct {
|
|
database Database
|
|
}
|
|
|
|
func NewService(database Database) *Service {
|
|
return &Service{database: database}
|
|
}
|
|
|
|
func (s *Service) Check(ctx context.Context) Status {
|
|
status := Status{}
|
|
if s.database != nil {
|
|
status.DatabaseReady = s.database.Ping(ctx) == nil
|
|
}
|
|
status.Serving = status.DatabaseReady
|
|
return status
|
|
}
|