refactor(routes): simplify route exclusion check and health check defaults

This commit is contained in:
yusing
2025-12-04 15:12:35 +08:00
parent f2e73af32f
commit 100eac1f3c
7 changed files with 30 additions and 50 deletions

View File

@@ -51,8 +51,10 @@ func NewMonitor(r types.Route) types.HealthMonCheck {
mon = NewAgentProxiedMonitor(r.GetAgent(), r.HealthCheckConfig(), AgentTargetFromURL(&r.TargetURL().URL))
} else {
switch r := r.(type) {
case types.HTTPRoute:
case types.ReverseProxyRoute:
mon = NewHTTPHealthMonitor(&r.TargetURL().URL, r.HealthCheckConfig())
case types.FileServerRoute:
mon = NewFileServerHealthMonitor(r.HealthCheckConfig(), r.RootPath())
case types.StreamRoute:
mon = NewRawHealthMonitor(&r.TargetURL().URL, r.HealthCheckConfig())
default:
@@ -71,15 +73,9 @@ func NewMonitor(r types.Route) types.HealthMonCheck {
return mon
}
func newMonitor(u *url.URL, config *types.HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
if config.Retries == 0 {
if config.Interval == 0 {
config.Interval = common.HealthCheckIntervalDefault
}
config.Retries = int64(common.HealthCheckDownNotifyDelayDefault / config.Interval)
}
cfg.ApplyDefaults(config.DefaultConfig().Defaults.HealthCheck)
mon := &monitor{
config: config,
config: cfg,
checkHealth: healthCheckFunc,
startTime: time.Now(),
notifyFunc: notif.Notify,