From 08b875155907c6f93694d3be6e8d8e67c159e084 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Fri, 14 Sep 2018 00:19:24 +0300 Subject: [PATCH] cmd/btcctl: use regexp.MustCompile for constant patterns Found using https://go-critic.github.io/overview#regexpMust-ref --- cmd/btcctl/config.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/cmd/btcctl/config.go b/cmd/btcctl/config.go index cd232a9e..282b1743 100644 --- a/cmd/btcctl/config.go +++ b/cmd/btcctl/config.go @@ -295,10 +295,7 @@ func createDefaultConfigFile(destinationPath, serverConfigPath string) error { } // Extract the rpcuser - rpcUserRegexp, err := regexp.Compile(`(?m)^\s*rpcuser=([^\s]+)`) - if err != nil { - return err - } + rpcUserRegexp := regexp.MustCompile(`(?m)^\s*rpcuser=([^\s]+)`) userSubmatches := rpcUserRegexp.FindSubmatch(content) if userSubmatches == nil { // No user found, nothing to do @@ -306,10 +303,7 @@ func createDefaultConfigFile(destinationPath, serverConfigPath string) error { } // Extract the rpcpass - rpcPassRegexp, err := regexp.Compile(`(?m)^\s*rpcpass=([^\s]+)`) - if err != nil { - return err - } + rpcPassRegexp := regexp.MustCompile(`(?m)^\s*rpcpass=([^\s]+)`) passSubmatches := rpcPassRegexp.FindSubmatch(content) if passSubmatches == nil { // No password found, nothing to do @@ -317,10 +311,7 @@ func createDefaultConfigFile(destinationPath, serverConfigPath string) error { } // Extract the notls - noTLSRegexp, err := regexp.Compile(`(?m)^\s*notls=(0|1)(?:\s|$)`) - if err != nil { - return err - } + noTLSRegexp := regexp.MustCompile(`(?m)^\s*notls=(0|1)(?:\s|$)`) noTLSSubmatches := noTLSRegexp.FindSubmatch(content) // Create the destination directory if it does not exists