Applied Copilot review suggestions

This commit is contained in:
2026-02-23 22:35:42 +01:00
parent a8204de914
commit d9a1bd9001
5 changed files with 79 additions and 53 deletions

View File

@@ -25,8 +25,8 @@ func NewConfig() *Config {
config := &Config{
DataPath: sanitizeDataPath(os.Getenv("DATA_PATH")),
Address: firstNonEmpty(strings.TrimSpace(os.Getenv("ADDRESS")), "0.0.0.0"),
Port: envInt("PORT", 3000),
ChunkSize: envInt("CHUNK_SIZE", 8192000),
Port: envIntRange("PORT", 3000, 1, 65535),
ChunkSize: envIntRange("CHUNK_SIZE", 8192000, 1, 64*1024*1024),
LogLevel: strings.ToLower(firstNonEmpty(strings.TrimSpace(os.Getenv("LOG_LEVEL")), "info")),
LogFormat: strings.ToLower(firstNonEmpty(strings.TrimSpace(os.Getenv("LOG_FORMAT")), strings.TrimSpace(os.Getenv("LOG_TYPE")), "text")),
AuditLog: envBool("AUDIT_LOG", true),
@@ -40,7 +40,7 @@ func NewConfig() *Config {
}
func envInt(key string, defaultValue int) int {
func envIntRange(key string, defaultValue, minValue, maxValue int) int {
raw := strings.TrimSpace(os.Getenv(key))
if raw == "" {
return defaultValue
@@ -49,6 +49,9 @@ func envInt(key string, defaultValue int) int {
if err != nil {
return defaultValue
}
if value < minValue || value > maxValue {
return defaultValue
}
return value
}