From 30d4f1125e85d2f00fc21fca330a32ab39630cc8 Mon Sep 17 00:00:00 2001 From: na4ma4 Date: Tue, 24 Oct 2023 14:49:05 +1000 Subject: [PATCH] [lint] fixed linter warnings --- cmd/traefik-acme/main.go | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/cmd/traefik-acme/main.go b/cmd/traefik-acme/main.go index 135797d..40aa833 100644 --- a/cmd/traefik-acme/main.go +++ b/cmd/traefik-acme/main.go @@ -62,7 +62,6 @@ func main() { _ = rootCmd.Execute() } -//nolint:nestif // ifElseChain doesn't seem to be idiomatic here. func writeFile(filename string, data []byte, perm os.FileMode) (bool, error) { if _, err := os.Stat(filename); os.IsNotExist(err) { // File does not exist, just write it. @@ -82,29 +81,29 @@ func writeFile(filename string, data []byte, perm os.FileMode) (bool, error) { } return true, nil - } else { - // File exists - logrus.WithField("filename", filename).Debugf("file found") + } - ld, lerr := os.ReadFile(filename) - if lerr != nil { - return false, fmt.Errorf("unable to read file for compare: %w", lerr) - } + // File exists + logrus.WithField("filename", filename).Debugf("file found") - if i := bytes.Compare(ld, data); i == 0 { - logrus.WithField("filename", filename).Debugf("file unchanged") + ld, lerr := os.ReadFile(filename) + if lerr != nil { + return false, fmt.Errorf("unable to read file for compare: %w", lerr) + } - return false, nil - } + if i := bytes.Compare(ld, data); i == 0 { + logrus.WithField("filename", filename).Debugf("file unchanged") - logrus.WithField("filename", filename).Debugf("file changed, writing") + return false, nil + } - if werr := os.WriteFile(filename, data, perm); werr != nil { - return true, fmt.Errorf("unable to write file: %w", werr) - } + logrus.WithField("filename", filename).Debugf("file changed, writing") - return true, nil + if werr := os.WriteFile(filename, data, perm); werr != nil { + return true, fmt.Errorf("unable to write file: %w", werr) } + + return true, nil } //nolint:nestif // mainCommand can stand a little complexity.