Shorten conditions

This commit is contained in:
Frank Denis 2019-12-09 10:07:05 +01:00
parent 96d15771e2
commit ba8565a59e
5 changed files with 9 additions and 20 deletions

View File

@ -706,12 +706,8 @@ func cdLocal() {
exeFileName, err := os.Executable()
if err != nil {
dlog.Warnf("Unable to determine the executable directory: [%s] -- You will need to specify absolute paths in the configuration file", err)
return
}
err = os.Chdir(filepath.Dir(exeFileName))
if err != nil {
dlog.Warnf("Unable to change working directory: %s", err)
} else if err = os.Chdir(filepath.Dir(exeFileName)); err != nil {
dlog.Warnf("Unable to change working directory to [%s]: %s", exeFileName, err)
}
}

View File

@ -226,12 +226,10 @@ func _dnsExchange(proxy *Proxy, proto string, query *dns.Msg, serverAddress stri
return nil, 0, err
}
defer pc.Close()
err = pc.SetDeadline(time.Now().Add(proxy.timeout))
if err != nil {
if err = pc.SetDeadline(time.Now().Add(proxy.timeout)); err != nil {
return nil, 0, err
}
_, err = pc.Write(binQuery)
if err != nil {
if _, err = pc.Write(binQuery); err != nil {
return nil, 0, err
}
packet = make([]byte, MaxDNSPacketSize)
@ -267,16 +265,14 @@ func _dnsExchange(proxy *Proxy, proto string, query *dns.Msg, serverAddress stri
return nil, 0, err
}
defer pc.Close()
err = pc.SetDeadline(time.Now().Add(proxy.timeout))
if err != nil {
if err = pc.SetDeadline(time.Now().Add(proxy.timeout)); err != nil {
return nil, 0, err
}
binQuery, err = PrefixWithSize(binQuery)
if err != nil {
return nil, 0, err
}
_, err = pc.Write(binQuery)
if err != nil {
if _, err = pc.Write(binQuery); err != nil {
return nil, 0, err
}
packet, err = ReadPrefixed(&pc)

View File

@ -151,8 +151,7 @@ func (plugin *PluginBlockIP) Eval(pluginsState *PluginsState, msg *dns.Msg) erro
if plugin.logger == nil {
return errors.New("Log file not initialized")
}
_, err := plugin.logger.Write([]byte(line))
if err != nil {
if _, err := plugin.logger.Write([]byte(line)); err != nil {
return err
}
}

View File

@ -66,8 +66,7 @@ func (blockedNames *BlockedNames) check(pluginsState *PluginsState, qName string
if blockedNames.logger == nil {
return false, errors.New("Log file not initialized")
}
_, err := blockedNames.logger.Write([]byte(line))
if err != nil {
if _, err := blockedNames.logger.Write([]byte(line)); err != nil {
return false, err
}
}

View File

@ -84,8 +84,7 @@ func (plugin *PluginCloak) Init(proxy *Proxy) error {
cloakedNames[line] = cloakedName
}
for line, cloakedName := range cloakedNames {
err = plugin.patternMatcher.Add(line, cloakedName, cloakedName.lineNo)
if err != nil {
if err = plugin.patternMatcher.Add(line, cloakedName, cloakedName.lineNo); err != nil {
return err
}
}