Skip to content

Commit 6f96816

Browse files
committed
Nits
1 parent 0af6d2e commit 6f96816

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

dnscrypt-proxy/config_loader.go

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ import (
1616
netproxy "golang.org/x/net/proxy"
1717
)
1818

19+
func normalizeLogFormat(format *string) {
20+
if len(*format) == 0 {
21+
*format = "tsv"
22+
} else {
23+
*format = strings.ToLower(*format)
24+
}
25+
}
26+
1927
// configureLogging - Configure logging based on the configuration
2028
func configureLogging(proxy *Proxy, flags *ConfigFlags, config *Config) {
2129
if config.LogLevel >= 0 && config.LogLevel < int(dlog.SeverityLast) {
@@ -279,11 +287,7 @@ func configureEDNSClientSubnet(proxy *Proxy, config *Config) error {
279287

280288
// configureQueryLog - Configures query logging
281289
func configureQueryLog(proxy *Proxy, config *Config) error {
282-
if len(config.QueryLog.Format) == 0 {
283-
config.QueryLog.Format = "tsv"
284-
} else {
285-
config.QueryLog.Format = strings.ToLower(config.QueryLog.Format)
286-
}
290+
normalizeLogFormat(&config.QueryLog.Format)
287291
if config.QueryLog.Format != "tsv" && config.QueryLog.Format != "ltsv" {
288292
return errors.New("Unsupported query log format")
289293
}
@@ -296,11 +300,7 @@ func configureQueryLog(proxy *Proxy, config *Config) error {
296300

297301
// configureNXLog - Configures NX domain logging
298302
func configureNXLog(proxy *Proxy, config *Config) error {
299-
if len(config.NxLog.Format) == 0 {
300-
config.NxLog.Format = "tsv"
301-
} else {
302-
config.NxLog.Format = strings.ToLower(config.NxLog.Format)
303-
}
303+
normalizeLogFormat(&config.NxLog.Format)
304304
if config.NxLog.Format != "tsv" && config.NxLog.Format != "ltsv" {
305305
return errors.New("Unsupported NX log format")
306306
}
@@ -321,11 +321,7 @@ func configureBlockedNames(proxy *Proxy, config *Config) error {
321321
config.BlockName.Format = config.BlockNameLegacy.Format
322322
config.BlockName.LogFile = config.BlockNameLegacy.LogFile
323323
}
324-
if len(config.BlockName.Format) == 0 {
325-
config.BlockName.Format = "tsv"
326-
} else {
327-
config.BlockName.Format = strings.ToLower(config.BlockName.Format)
328-
}
324+
normalizeLogFormat(&config.BlockName.Format)
329325
if config.BlockName.Format != "tsv" && config.BlockName.Format != "ltsv" {
330326
return errors.New("Unsupported block log format")
331327
}
@@ -347,11 +343,7 @@ func configureAllowedNames(proxy *Proxy, config *Config) error {
347343
config.AllowedName.Format = config.WhitelistNameLegacy.Format
348344
config.AllowedName.LogFile = config.WhitelistNameLegacy.LogFile
349345
}
350-
if len(config.AllowedName.Format) == 0 {
351-
config.AllowedName.Format = "tsv"
352-
} else {
353-
config.AllowedName.Format = strings.ToLower(config.AllowedName.Format)
354-
}
346+
normalizeLogFormat(&config.AllowedName.Format)
355347
if config.AllowedName.Format != "tsv" && config.AllowedName.Format != "ltsv" {
356348
return errors.New("Unsupported allowed_names log format")
357349
}
@@ -373,11 +365,7 @@ func configureBlockedIPs(proxy *Proxy, config *Config) error {
373365
config.BlockIP.Format = config.BlockIPLegacy.Format
374366
config.BlockIP.LogFile = config.BlockIPLegacy.LogFile
375367
}
376-
if len(config.BlockIP.Format) == 0 {
377-
config.BlockIP.Format = "tsv"
378-
} else {
379-
config.BlockIP.Format = strings.ToLower(config.BlockIP.Format)
380-
}
368+
normalizeLogFormat(&config.BlockIP.Format)
381369
if config.BlockIP.Format != "tsv" && config.BlockIP.Format != "ltsv" {
382370
return errors.New("Unsupported IP block log format")
383371
}
@@ -390,11 +378,7 @@ func configureBlockedIPs(proxy *Proxy, config *Config) error {
390378

391379
// configureAllowedIPs - Configures allowed IPs
392380
func configureAllowedIPs(proxy *Proxy, config *Config) error {
393-
if len(config.AllowIP.Format) == 0 {
394-
config.AllowIP.Format = "tsv"
395-
} else {
396-
config.AllowIP.Format = strings.ToLower(config.AllowIP.Format)
397-
}
381+
normalizeLogFormat(&config.AllowIP.Format)
398382
if config.AllowIP.Format != "tsv" && config.AllowIP.Format != "ltsv" {
399383
return errors.New("Unsupported allowed_ips log format")
400384
}

0 commit comments

Comments
 (0)