proxy-pool/internal/config/effective_check.go
youfak bea790f1d4
Some checks are pending
ci / proto (push) Waiting to run
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
ci / race (push) Waiting to run
ci / integration (push) Waiting to run
feat: add controller health reducer
2026-07-31 18:13:47 +08:00

42 lines
1.1 KiB
Go

package config
// EffectiveCheck overlays one upstream's non-zero check fields on the global
// defaults. A non-nil URL slice is an explicit override, including an empty
// slice that intentionally disables URL-based EGRESS checks for that upstream.
func EffectiveCheck(defaults, override Check) Check {
effective := defaults
if override.Interval != 0 {
effective.Interval = override.Interval
}
if override.Jitter != 0 {
effective.Jitter = override.Jitter
}
if override.MaxInFlight != 0 {
effective.MaxInFlight = override.MaxInFlight
}
if override.Timeout != 0 {
effective.Timeout = override.Timeout
}
if override.MaxAttempts != 0 {
effective.MaxAttempts = override.MaxAttempts
}
if override.MaxConsecutiveFailures != 0 {
effective.MaxConsecutiveFailures = override.MaxConsecutiveFailures
}
if override.URLs != nil {
effective.URLs = cloneCheckURLs(override.URLs)
} else {
effective.URLs = cloneCheckURLs(defaults.URLs)
}
return effective
}
func cloneCheckURLs(source []string) []string {
if source == nil {
return nil
}
result := make([]string, len(source))
copy(result, source)
return result
}