cmd/btcctl: use regexp.MustCompile for constant patterns

Found using https://go-critic.github.io/overview#regexpMust-ref
This commit is contained in:
Iskander Sharipov 2018-09-14 00:19:24 +03:00 committed by John C. Vernaleo
parent cfcf4fb762
commit 08b8751559

View file

@ -295,10 +295,7 @@ func createDefaultConfigFile(destinationPath, serverConfigPath string) error {
} }
// Extract the rpcuser // Extract the rpcuser
rpcUserRegexp, err := regexp.Compile(`(?m)^\s*rpcuser=([^\s]+)`) rpcUserRegexp := regexp.MustCompile(`(?m)^\s*rpcuser=([^\s]+)`)
if err != nil {
return err
}
userSubmatches := rpcUserRegexp.FindSubmatch(content) userSubmatches := rpcUserRegexp.FindSubmatch(content)
if userSubmatches == nil { if userSubmatches == nil {
// No user found, nothing to do // No user found, nothing to do
@ -306,10 +303,7 @@ func createDefaultConfigFile(destinationPath, serverConfigPath string) error {
} }
// Extract the rpcpass // Extract the rpcpass
rpcPassRegexp, err := regexp.Compile(`(?m)^\s*rpcpass=([^\s]+)`) rpcPassRegexp := regexp.MustCompile(`(?m)^\s*rpcpass=([^\s]+)`)
if err != nil {
return err
}
passSubmatches := rpcPassRegexp.FindSubmatch(content) passSubmatches := rpcPassRegexp.FindSubmatch(content)
if passSubmatches == nil { if passSubmatches == nil {
// No password found, nothing to do // No password found, nothing to do
@ -317,10 +311,7 @@ func createDefaultConfigFile(destinationPath, serverConfigPath string) error {
} }
// Extract the notls // Extract the notls
noTLSRegexp, err := regexp.Compile(`(?m)^\s*notls=(0|1)(?:\s|$)`) noTLSRegexp := regexp.MustCompile(`(?m)^\s*notls=(0|1)(?:\s|$)`)
if err != nil {
return err
}
noTLSSubmatches := noTLSRegexp.FindSubmatch(content) noTLSSubmatches := noTLSRegexp.FindSubmatch(content)
// Create the destination directory if it does not exists // Create the destination directory if it does not exists