-
Notifications
You must be signed in to change notification settings - Fork 7
/
factory.go
36 lines (29 loc) · 1.18 KB
/
factory.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
package healthcheck
// CheckerFactory is the interface for [Checker] factories.
type CheckerFactory interface {
Create(options ...CheckerOption) (*Checker, error)
}
// DefaultCheckerFactory is the default [CheckerFactory] implementation.
type DefaultCheckerFactory struct{}
// NewDefaultCheckerFactory returns a [DefaultCheckerFactory], implementing [CheckerFactory].
func NewDefaultCheckerFactory() CheckerFactory {
return &DefaultCheckerFactory{}
}
// Create returns a new [Checker], and accepts a list of [CheckerOption].
// For example:
//
// checker, _ := healthcheck.NewDefaultCheckerFactory().Create(
// healthcheck.WithProbe(NewSomeProbe()), // registers for startup, readiness and liveness
// healthcheck.WithProbe(NewOtherProbe(), healthcheck.Liveness), // registers for liveness only
// )
func (f *DefaultCheckerFactory) Create(options ...CheckerOption) (*Checker, error) {
appliedOpts := DefaultCheckerOptions()
for _, applyOpt := range options {
applyOpt(&appliedOpts)
}
checker := NewChecker()
for _, registration := range appliedOpts.Registrations {
checker.RegisterProbe(registration.Probe(), registration.Kinds()...)
}
return checker, nil
}