From dc49d309aee88f697b2cb391c832a25fa00efa40 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Wed, 5 Jul 2023 11:05:22 +0800 Subject: [PATCH] chore: use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) Signed-off-by: guoguangwu --- throttler/pfctl.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/throttler/pfctl.go b/throttler/pfctl.go index b868841..dd9effb 100644 --- a/throttler/pfctl.go +++ b/throttler/pfctl.go @@ -1,7 +1,6 @@ package throttler import ( - "errors" "fmt" "strconv" "strings" @@ -48,13 +47,13 @@ func (i *pfctlThrottler) setup(c *Config) error { // Enable firewall err := i.c.execute(pfctlEnableFirewall) if err != nil { - return errors.New(fmt.Sprintf("Could not enable firewall using: `%s`. Error: %s", pfctlEnableFirewall, err.Error())) + return fmt.Errorf("Could not enable firewall using: `%s`. Error: %s", pfctlEnableFirewall, err.Error()) } // Add the dummynet and anchor err = i.c.execute(pfctlCreateAnchor) if err != nil { - return errors.New(fmt.Sprintf("Could not create anchor rule for dummynet using: `%s`. Error: %s", pfctlCreateAnchor, err.Error())) + return fmt.Errorf("Could not create anchor rule for dummynet using: `%s`. Error: %s", pfctlCreateAnchor, err.Error()) } // Add 'execute' portion of the command @@ -63,7 +62,7 @@ func (i *pfctlThrottler) setup(c *Config) error { err = i.c.execute(cmd) if err != nil { - return errors.New(fmt.Sprintf("Could not create dummynet using: `%s`. Error: %s", input, err.Error())) + return fmt.Errorf("Could not create dummynet using: `%s`. Error: %s", input, err.Error()) } // Apply the shaping etc. @@ -82,19 +81,19 @@ func (i *pfctlThrottler) teardown(_ *Config) error { // Reset firewall rules, leave it running err := i.c.execute(pfctlTeardown) if err != nil { - return errors.New(fmt.Sprintf("Could not remove firewall rules using: `%s`. Error: %s", pfctlTeardown, err.Error())) + return fmt.Errorf("Could not remove firewall rules using: `%s`. Error: %s", pfctlTeardown, err.Error()) } // Turn off the firewall, discarding any rules err = i.c.execute(pfctlDisableFirewall) if err != nil { - return errors.New(fmt.Sprintf("Could not disable firewall using: `%s`. Error: %s", pfctlDisableFirewall, err.Error())) + return fmt.Errorf("Could not disable firewall using: `%s`. Error: %s", pfctlDisableFirewall, err.Error()) } // Disable dnctl rules err = i.c.execute(dnctlTeardown) if err != nil { - return errors.New(fmt.Sprintf("Could not disable dnctl rules using: `%s`. Error: %s", dnctlTeardown, err.Error())) + return fmt.Errorf("Could not disable dnctl rules using: `%s`. Error: %s", dnctlTeardown, err.Error()) } return nil