fix: resolve lint errors in webui_gateway validation
- commit
- b5135b099bd687ba71ee22357253bb26696def2b
- author
- brice · · 2025-12-29 17:35 UTC
- parent
- 5bc7d83
- signature
- unsigned
1 file · +16 -9
M internal/infrastructure/config/webui_gateway.go +16 -9
| @@ -15,13 +15,20 @@ func NewWebUIConfigGateway(mgr *Manager) *WebUIConfigGateway { | |||
| 15 | 15 | return &WebUIConfigGateway{mgr: mgr} | |
| 16 | 16 | } | |
| 17 | 17 | ||
| 18 | - | // clampInt returns v clamped to [min, max]. | |
| 19 | - | func clampInt(v, min, max int) int { | |
| 20 | - | if v < min { | |
| 21 | - | return min | |
| 18 | + | // Validation limits for custom performance fields. | |
| 19 | + | const ( | |
| 20 | + | maxWebProcessMemoryMB = 16384 | |
| 21 | + | maxNetworkProcessMemoryMB = 4096 | |
| 22 | + | maxWebViewPoolPrewarm = 20 | |
| 23 | + | ) | |
| 24 | + | ||
| 25 | + | // clampInt returns v clamped to [lo, hi]. | |
| 26 | + | func clampInt(v, lo, hi int) int { | |
| 27 | + | if v < lo { | |
| 28 | + | return lo | |
| 22 | 29 | } | |
| 23 | - | if v > max { | |
| 24 | - | return max | |
| 30 | + | if v > hi { | |
| 31 | + | return hi | |
| 25 | 32 | } | |
| 26 | 33 | return v | |
| 27 | 34 | } | |
| @@ -80,9 +87,9 @@ func (g *WebUIConfigGateway) SaveWebUIConfig(ctx context.Context, cfg port.WebUI | |||
| 80 | 87 | if cfg.Performance.Profile == string(ProfileCustom) { | |
| 81 | 88 | current.Performance.SkiaCPUPaintingThreads = clampInt(cfg.Performance.Custom.SkiaCPUThreads, 0, maxSkiaCPUThreads) | |
| 82 | 89 | current.Performance.SkiaGPUPaintingThreads = clampInt(cfg.Performance.Custom.SkiaGPUThreads, -1, maxSkiaCPUThreads) | |
| 83 | - | current.Performance.WebProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.WebProcessMemoryMB, 0, 16384) | |
| 84 | - | current.Performance.NetworkProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.NetworkProcessMemoryMB, 0, 4096) | |
| 85 | - | current.Performance.WebViewPoolPrewarmCount = clampInt(cfg.Performance.Custom.WebViewPoolPrewarm, 0, 20) | |
| 90 | + | current.Performance.WebProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.WebProcessMemoryMB, 0, maxWebProcessMemoryMB) | |
| 91 | + | current.Performance.NetworkProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.NetworkProcessMemoryMB, 0, maxNetworkProcessMemoryMB) | |
| 92 | + | current.Performance.WebViewPoolPrewarmCount = clampInt(cfg.Performance.Custom.WebViewPoolPrewarm, 0, maxWebViewPoolPrewarm) | |
| 86 | 93 | } | |
| 87 | 94 | ||
| 88 | 95 | return g.mgr.Save(current) | |
| @@ -15,13 +15,20 @@ func NewWebUIConfigGateway(mgr *Manager) *WebUIConfigGateway { | |||||
| 15 | return &WebUIConfigGateway{mgr: mgr} | 15 | return &WebUIConfigGateway{mgr: mgr} | ||
| 16 | } | 16 | } | ||
| 17 | 17 | ||||
| 18 | - | // clampInt returns v clamped to [min, max]. | 18 | + | // Validation limits for custom performance fields. |
| 19 | - | func clampInt(v, min, max int) int { | 19 | + | const ( |
| 20 | - | if v < min { | 20 | + | maxWebProcessMemoryMB = 16384 |
| 21 | - | return min | 21 | + | maxNetworkProcessMemoryMB = 4096 |
| 22 | + | maxWebViewPoolPrewarm = 20 | |||
| 23 | + | ) | |||
| 24 | + | ||||
| 25 | + | // clampInt returns v clamped to [lo, hi]. | |||
| 26 | + | func clampInt(v, lo, hi int) int { | |||
| 27 | + | if v < lo { | |||
| 28 | + | return lo | |||
| 22 | } | 29 | } | ||
| 23 | - | if v > max { | 30 | + | if v > hi { |
| 24 | - | return max | 31 | + | return hi |
| 25 | } | 32 | } | ||
| 26 | return v | 33 | return v | ||
| 27 | } | 34 | } | ||
| @@ -80,9 +87,9 @@ func (g *WebUIConfigGateway) SaveWebUIConfig(ctx context.Context, cfg port.WebUI | |||||
| 80 | if cfg.Performance.Profile == string(ProfileCustom) { | 87 | if cfg.Performance.Profile == string(ProfileCustom) { | ||
| 81 | current.Performance.SkiaCPUPaintingThreads = clampInt(cfg.Performance.Custom.SkiaCPUThreads, 0, maxSkiaCPUThreads) | 88 | current.Performance.SkiaCPUPaintingThreads = clampInt(cfg.Performance.Custom.SkiaCPUThreads, 0, maxSkiaCPUThreads) | ||
| 82 | current.Performance.SkiaGPUPaintingThreads = clampInt(cfg.Performance.Custom.SkiaGPUThreads, -1, maxSkiaCPUThreads) | 89 | current.Performance.SkiaGPUPaintingThreads = clampInt(cfg.Performance.Custom.SkiaGPUThreads, -1, maxSkiaCPUThreads) | ||
| 83 | - | current.Performance.WebProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.WebProcessMemoryMB, 0, 16384) | 90 | + | current.Performance.WebProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.WebProcessMemoryMB, 0, maxWebProcessMemoryMB) |
| 84 | - | current.Performance.NetworkProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.NetworkProcessMemoryMB, 0, 4096) | 91 | + | current.Performance.NetworkProcessMemoryLimitMB = clampInt(cfg.Performance.Custom.NetworkProcessMemoryMB, 0, maxNetworkProcessMemoryMB) |
| 85 | - | current.Performance.WebViewPoolPrewarmCount = clampInt(cfg.Performance.Custom.WebViewPoolPrewarm, 0, 20) | 92 | + | current.Performance.WebViewPoolPrewarmCount = clampInt(cfg.Performance.Custom.WebViewPoolPrewarm, 0, maxWebViewPoolPrewarm) |
| 86 | } | 93 | } | ||
| 87 | 94 | ||||
| 88 | return g.mgr.Save(current) | 95 | return g.mgr.Save(current) | ||