Commit 1a09953
authored
refactor: remove redundant config default fallbacks in server and launcher (#3032)
## Summary
Removes duplicated config default logic identified in #2983 / #2984.
Consumer code in `unified.go` and `launcher.go` re-implemented config
field defaults that the config loading layer already guarantees.
## Changes
### New: `Config.EnsureGatewayDefaults()` (`config_core.go`)
Exported method that guarantees `cfg.Gateway` is non-nil and all
gateway-level + feature defaults are applied. This makes the config
loading contract explicit and safe for any consumer — including test
code that constructs configs manually without going through
`LoadFromFile`/`LoadFromStdin`.
### Simplified: `internal/server/unified.go`
**Before** (3 nil-guard + fallback blocks, 18 lines):
```go
payloadDir := config.DefaultPayloadDir
if cfg.Gateway != nil && cfg.Gateway.PayloadDir != "" {
payloadDir = cfg.Gateway.PayloadDir
}
// ... repeated for PayloadPathPrefix, PayloadSizeThreshold
```
**After** (direct field access, 3 lines):
```go
cfg.EnsureGatewayDefaults()
payloadDir := cfg.Gateway.PayloadDir
payloadPathPrefix := cfg.Gateway.PayloadPathPrefix
payloadSizeThreshold := cfg.Gateway.PayloadSizeThreshold
```
### Simplified: `internal/launcher/launcher.go`
**Before** (nil-guard + fallback + branch logging, 8 lines):
```go
startupTimeout := time.Duration(config.DefaultStartupTimeout) * time.Second
if cfg.Gateway != nil && cfg.Gateway.StartupTimeout > 0 {
startupTimeout = time.Duration(cfg.Gateway.StartupTimeout) * time.Second
}
```
**After** (direct access, 2 lines):
```go
cfg.EnsureGatewayDefaults()
startupTimeout := time.Duration(cfg.Gateway.StartupTimeout) * time.Second
```
### Updated: `launcher_test.go`
Updated test name and comment for `TestLauncher_TimeoutWithNilGateway`
to document that `EnsureGatewayDefaults` now handles the nil case.
## Why EnsureGatewayDefaults instead of just removing nil-guards?
100+ test files construct `config.Config{}` without setting `Gateway`.
Rather than touching all of them, `EnsureGatewayDefaults()` provides a
single defensive call that makes the contract explicit while keeping
existing tests working.
Closes #2983
Closes #29844 files changed
Lines changed: 30 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
201 | 214 | | |
202 | 215 | | |
203 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
| 530 | + | |
530 | 531 | | |
531 | 532 | | |
532 | 533 | | |
| |||
606 | 607 | | |
607 | 608 | | |
608 | 609 | | |
609 | | - | |
| 610 | + | |
| 611 | + | |
610 | 612 | | |
611 | 613 | | |
612 | 614 | | |
| |||
615 | 617 | | |
616 | 618 | | |
617 | 619 | | |
618 | | - | |
| 620 | + | |
619 | 621 | | |
620 | 622 | | |
621 | 623 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 113 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 114 | + | |
126 | 115 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
132 | 121 | | |
133 | 122 | | |
134 | 123 | | |
| |||
0 commit comments