From c482abb00c01164d3b81873a296a3f35a4755c1c Mon Sep 17 00:00:00 2001 From: Aaron Hurt Date: Fri, 19 Apr 2024 08:42:19 -0500 Subject: [PATCH] minor linter cleanup --- README.md | 2 +- command/check/command.go | 4 ++-- command/check/util.go | 2 +- command/update/command.go | 5 ++--- command/update/util.go | 2 +- commands.go | 2 +- common/dns/godaddy/godaddy.go | 4 ++-- common/errors.go | 6 +++--- main.go | 4 ++-- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 04db340..8d1e621 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Summary IPman is a simple tool to automatically update DNS records (A and AAAA) based on the external local IPv4 and/or IPv6 -address of the local machine. Currently it uses ipify.com for the external address lookup and supports writing +address of the local machine. It uses ipify.com for the external address lookup and supports writing records to GoDaddy's DNS API. Both backend providers are modeled as interfaces to allow adding additional backends as needed in the future. diff --git a/command/check/command.go b/command/check/command.go index fa839ed..959dcc9 100644 --- a/command/check/command.go +++ b/command/check/command.go @@ -29,13 +29,13 @@ func (c *Command) Run(args []string) int { // init flags if err = c.setupFlags(args); err != nil { - c.Log.Printf("[Error] Failed to init flags: %s", err.Error()) + c.Log.Printf("[Error] Failed to init flags: %w", err) return 1 } // check ip if err = c.checkIP(); err != nil { - c.Log.Printf("[Error] Failed to check addresses: %s", err.Error()) + c.Log.Printf("[Error] Failed to check addresses: %w", err) return 1 } diff --git a/command/check/util.go b/command/check/util.go index e5ea3da..566d671 100644 --- a/command/check/util.go +++ b/command/check/util.go @@ -21,7 +21,7 @@ func (c *Command) setupFlags(args []string) error { // init flagset cmdFlags = flag.NewFlagSet("check", flag.ContinueOnError) - cmdFlags.Usage = func() { fmt.Fprint(os.Stdout, c.Help()); os.Exit(0) } + cmdFlags.Usage = func() { _, _ = fmt.Fprint(os.Stdout, c.Help()); os.Exit(0) } // declare flags cmdFlags.BoolVar(&c.config.v4, "4", false, diff --git a/command/update/command.go b/command/update/command.go index 1d12377..6d4cb97 100644 --- a/command/update/command.go +++ b/command/update/command.go @@ -37,14 +37,13 @@ func (c *Command) Run(args []string) int { // init flags if err = c.setupFlags(args); err != nil { - c.Log.Printf("[Error] Failed to init flags: %s", err.Error()) + c.Log.Printf("[Error] Failed to init flags: %w", err) return 1 } // attempt to update p if err = c.updateIP(); err != nil { - c.Log.Printf("[Error] Failed to update dns record: %s", - err.Error()) + c.Log.Printf("[Error] Failed to update dns record: %w", err) return 1 } diff --git a/command/update/util.go b/command/update/util.go index c99373b..206769c 100644 --- a/command/update/util.go +++ b/command/update/util.go @@ -21,7 +21,7 @@ func (c *Command) setupFlags(args []string) error { // init flagset cmdFlags = flag.NewFlagSet("update", flag.ContinueOnError) - cmdFlags.Usage = func() { fmt.Fprint(os.Stdout, c.Help()); os.Exit(0) } + cmdFlags.Usage = func() { _, _ = fmt.Fprint(os.Stdout, c.Help()); os.Exit(0) } // declare flags cmdFlags.BoolVar(&c.config.v4, "4", false, diff --git a/commands.go b/commands.go index 156fc8b..e4e19bf 100644 --- a/commands.go +++ b/commands.go @@ -15,7 +15,7 @@ import ( var logger = stdLog.New(os.Stderr, "", stdLog.LstdFlags) // init command factory -func initComands() map[string]cli.CommandFactory { +func initCommands() map[string]cli.CommandFactory { // register sub commands return map[string]cli.CommandFactory{ "check": func() (cli.Command, error) { diff --git a/common/dns/godaddy/godaddy.go b/common/dns/godaddy/godaddy.go index d04b42b..d354fbf 100644 --- a/common/dns/godaddy/godaddy.go +++ b/common/dns/godaddy/godaddy.go @@ -117,8 +117,8 @@ func parseError(resp *http.Response) error { // attempt process error body if err = json.NewDecoder(resp.Body).Decode(obj); err != nil { - return fmt.Errorf("Unable to process error from %d error response: %s", - resp.StatusCode, err.Error()) + return fmt.Errorf("unable decode %d error response: %w", + resp.StatusCode, err) } // check for fields diff --git a/common/errors.go b/common/errors.go index fecd455..0cd4a7b 100644 --- a/common/errors.go +++ b/common/errors.go @@ -5,10 +5,10 @@ import ( ) // ErrUnknownArg is returned when non-flag arguments are present after the command -var ErrUnknownArg = errors.New("Unknown non-flag argument(s) present after command") +var ErrUnknownArg = errors.New("unknown non-flag argument(s) present after command") // ErrUnknownIPBackend is returned when an unknown IP backend is specified on the cli -var ErrUnknownIPBackend = errors.New("Unknown IP backend specified for command") +var ErrUnknownIPBackend = errors.New("unknown IP backend specified for command") // ErrUnknownDNSBackend is returned when an unknown DNS backend is specified on the cli -var ErrUnknownDNSBackend = errors.New("Unknown DNS backend specified for command") +var ErrUnknownDNSBackend = errors.New("unknown DNS backend specified for command") diff --git a/main.go b/main.go index 44da898..1a1ca13 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,8 @@ func main() { // init and populate cli object c = cli.NewCLI(appName, appVersion) - c.Args = os.Args[1:] // arguments minus command - c.Commands = initComands() // see commands.go + c.Args = os.Args[1:] // arguments minus command + c.Commands = initCommands() // see commands.go // run command and check return if status, err = c.Run(); err != nil {