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() exeFileName, err := os.Executable()
if err != nil { if err != nil {
dlog.Warnf("Unable to determine the executable directory: [%s] -- You will need to specify absolute paths in the configuration file", err) dlog.Warnf("Unable to determine the executable directory: [%s] -- You will need to specify absolute paths in the configuration file", err)
return } else if err = os.Chdir(filepath.Dir(exeFileName)); err != nil {
} dlog.Warnf("Unable to change working directory to [%s]: %s", exeFileName, err)
err = os.Chdir(filepath.Dir(exeFileName))
if err != nil {
dlog.Warnf("Unable to change working directory: %s", err)
} }
} }

View File

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

View File

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

View File

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

View File

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