From ba8565a59e35c3d549062a19ca199d971a7202e0 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 9 Dec 2019 10:07:05 +0100 Subject: [PATCH] Shorten conditions --- dnscrypt-proxy/config.go | 8 ++------ dnscrypt-proxy/dnscrypt_certs.go | 12 ++++-------- dnscrypt-proxy/plugin_block_ip.go | 3 +-- dnscrypt-proxy/plugin_block_name.go | 3 +-- dnscrypt-proxy/plugin_cloak.go | 3 +-- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index c6d01c17..d47befe9 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -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) } } diff --git a/dnscrypt-proxy/dnscrypt_certs.go b/dnscrypt-proxy/dnscrypt_certs.go index 63ddd468..c1c19b70 100644 --- a/dnscrypt-proxy/dnscrypt_certs.go +++ b/dnscrypt-proxy/dnscrypt_certs.go @@ -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) diff --git a/dnscrypt-proxy/plugin_block_ip.go b/dnscrypt-proxy/plugin_block_ip.go index 5989fa59..f6654ee9 100644 --- a/dnscrypt-proxy/plugin_block_ip.go +++ b/dnscrypt-proxy/plugin_block_ip.go @@ -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 } } diff --git a/dnscrypt-proxy/plugin_block_name.go b/dnscrypt-proxy/plugin_block_name.go index 5ae1d280..03955291 100644 --- a/dnscrypt-proxy/plugin_block_name.go +++ b/dnscrypt-proxy/plugin_block_name.go @@ -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 } } diff --git a/dnscrypt-proxy/plugin_cloak.go b/dnscrypt-proxy/plugin_cloak.go index 11a7f9e9..ad595ce0 100644 --- a/dnscrypt-proxy/plugin_cloak.go +++ b/dnscrypt-proxy/plugin_cloak.go @@ -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 } }