45 lines
1.2 KiB
Go
45 lines
1.2 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.UnhealthyRemoveAfter != 0 {
|
|
effective.UnhealthyRemoveAfter = override.UnhealthyRemoveAfter
|
|
}
|
|
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
|
|
}
|