core/internal/health/config.go

44 lines
727 B
Go

package health
import "runtime"
type config struct {
liveChecks []Checker
readyChecks []Checker
maxConcurrent int
}
type Option func(cfg *config)
const maxConcurrentDefault = 5
func newConfig(opts ...Option) *config {
cfg := &config{
maxConcurrent: min(runtime.NumCPU(), maxConcurrentDefault),
}
for _, opt := range opts {
opt(cfg)
}
return cfg
}
func WithMaxConcurrent(max int) Option {
return func(cfg *config) {
cfg.maxConcurrent = max
}
}
func WithLiveCheck(check Checker) Option {
return func(cfg *config) {
cfg.liveChecks = append(cfg.liveChecks, check)
}
}
func WithReadyCheck(check Checker) Option {
return func(cfg *config) {
cfg.readyChecks = append(cfg.readyChecks, check)
}
}