Skip to content

Commit

Permalink
lxc: fix go-vet linter
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Sep 4, 2024
1 parent e7c8b54 commit 40bae5c
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 107 deletions.
11 changes: 6 additions & 5 deletions lxc/action.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -160,7 +161,7 @@ func (c *cmdAction) Command(action string) *cobra.Command {
func (c *cmdAction) doActionAll(action string, resource remoteResource) error {
if resource.name != "" {
// both --all and instance name given.
return fmt.Errorf(i18n.G("Both --all and instance name given"))
return errors.New(i18n.G("Both --all and instance name given"))
}

remote := resource.remote
Expand Down Expand Up @@ -232,7 +233,7 @@ func (c *cmdAction) doAction(action string, conf *config.Config, nameArg string)
}

if action == "stop" && c.flagForce && c.flagConsole != "" {
return fmt.Errorf(i18n.G("--console can't be used while forcing instance shutdown"))
return errors.New(i18n.G("--console can't be used while forcing instance shutdown"))
}

remote, name, err := conf.ParseRemote(nameArg)
Expand Down Expand Up @@ -337,7 +338,7 @@ func (c *cmdAction) run(cmd *cobra.Command, args []string) error {
for _, resource := range resources {
// We don't allow instance names with --all.
if resource.name != "" {
return fmt.Errorf(i18n.G("Both --all and instance name given"))
return errors.New(i18n.G("Both --all and instance name given"))
}

// See if we can use the bulk API.
Expand Down Expand Up @@ -381,11 +382,11 @@ func (c *cmdAction) run(cmd *cobra.Command, args []string) error {

if c.flagConsole != "" {
if c.flagAll {
return fmt.Errorf(i18n.G("--console can't be used with --all"))
return errors.New(i18n.G("--console can't be used with --all"))
}

if len(names) != 1 {
return fmt.Errorf(i18n.G("--console only works with a single instance"))
return errors.New(i18n.G("--console only works with a single instance"))
}
}

Expand Down
5 changes: 3 additions & 2 deletions lxc/cluster_role.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -78,7 +79,7 @@ func (c *cmdClusterRoleAdd) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing cluster member name"))
return errors.New(i18n.G("Missing cluster member name"))
}

// Extract the current value
Expand Down Expand Up @@ -146,7 +147,7 @@ func (c *cmdClusterRoleRemove) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing cluster member name"))
return errors.New(i18n.G("Missing cluster member name"))
}

// Extract the current value
Expand Down
33 changes: 17 additions & 16 deletions lxc/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -166,7 +167,7 @@ func (c *cmdConfigEdit) run(cmd *cobra.Command, args []string) error {
if resource.name != "" {
// Quick checks.
if c.config.flagTarget != "" {
return fmt.Errorf(i18n.G("--target cannot be used with instances"))
return errors.New(i18n.G("--target cannot be used with instances"))
}

// If stdin isn't a terminal, read text from it
Expand Down Expand Up @@ -302,7 +303,7 @@ func (c *cmdConfigEdit) run(cmd *cobra.Command, args []string) error {
// Targeting
if c.config.flagTarget != "" {
if !resource.server.IsClustered() {
return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster"))
return errors.New(i18n.G("To use --target, the destination remote must be a cluster"))
}

resource.server = resource.server.UseTarget(c.config.flagTarget)
Expand Down Expand Up @@ -439,7 +440,7 @@ func (c *cmdConfigGet) run(cmd *cobra.Command, args []string) error {
if resource.name != "" {
// Quick checks.
if c.config.flagTarget != "" {
return fmt.Errorf(i18n.G("--target cannot be used with instances"))
return errors.New(i18n.G("--target cannot be used with instances"))
}

if isSnapshot {
Expand Down Expand Up @@ -489,13 +490,13 @@ func (c *cmdConfigGet) run(cmd *cobra.Command, args []string) error {
} else {
// Quick check.
if c.flagExpanded {
return fmt.Errorf(i18n.G("--expanded cannot be used with a server"))
return errors.New(i18n.G("--expanded cannot be used with a server"))
}

// Targeting
if c.config.flagTarget != "" {
if !resource.server.IsClustered() {
return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster"))
return errors.New(i18n.G("To use --target, the destination remote must be a cluster"))
}

resource.server = resource.server.UseTarget(c.config.flagTarget)
Expand Down Expand Up @@ -624,7 +625,7 @@ func (c *cmdConfigSet) run(cmd *cobra.Command, args []string) error {
if resource.name != "" {
// Quick checks.
if c.config.flagTarget != "" {
return fmt.Errorf(i18n.G("--target cannot be used with instances"))
return errors.New(i18n.G("--target cannot be used with instances"))
}

keys, err := getConfig(args[1:]...)
Expand Down Expand Up @@ -662,7 +663,7 @@ func (c *cmdConfigSet) run(cmd *cobra.Command, args []string) error {
return op.Wait()
}

return fmt.Errorf(i18n.G("There is no config key to set on an instance snapshot."))
return errors.New(i18n.G("There is no config key to set on an instance snapshot."))
}

inst, etag, err := resource.server.GetInstance(resource.name)
Expand Down Expand Up @@ -711,7 +712,7 @@ func (c *cmdConfigSet) run(cmd *cobra.Command, args []string) error {
// Targeting
if c.config.flagTarget != "" {
if !resource.server.IsClustered() {
return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster"))
return errors.New(i18n.G("To use --target, the destination remote must be a cluster"))
}

resource.server = resource.server.UseTarget(c.config.flagTarget)
Expand Down Expand Up @@ -805,13 +806,13 @@ func (c *cmdConfigShow) run(cmd *cobra.Command, args []string) error {
if resource.name == "" {
// Quick check.
if c.flagExpanded {
return fmt.Errorf(i18n.G("--expanded cannot be used with a server"))
return errors.New(i18n.G("--expanded cannot be used with a server"))
}

// Targeting
if c.config.flagTarget != "" {
if !resource.server.IsClustered() {
return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster"))
return errors.New(i18n.G("To use --target, the destination remote must be a cluster"))
}

resource.server = resource.server.UseTarget(c.config.flagTarget)
Expand All @@ -831,7 +832,7 @@ func (c *cmdConfigShow) run(cmd *cobra.Command, args []string) error {
} else {
// Quick checks.
if c.config.flagTarget != "" {
return fmt.Errorf(i18n.G("--target cannot be used with instances"))
return errors.New(i18n.G("--target cannot be used with instances"))
}

// Instance or snapshot config
Expand Down Expand Up @@ -1004,7 +1005,7 @@ func (c *cmdConfigUefiGet) run(cmd *cobra.Command, args []string) error {

resource := resources[0]
if resource.name == "" {
return fmt.Errorf(i18n.G("Instance name must be specified"))
return errors.New(i18n.G("Instance name must be specified"))
}

// Get the UEFI variable
Expand All @@ -1015,7 +1016,7 @@ func (c *cmdConfigUefiGet) run(cmd *cobra.Command, args []string) error {

efiVariable, ok := resp.Variables[args[len(args)-1]]
if !ok {
return fmt.Errorf(i18n.G("Requested UEFI variable does not exist"))
return errors.New(i18n.G("Requested UEFI variable does not exist"))
}

fmt.Println(efiVariable.Data)
Expand Down Expand Up @@ -1062,7 +1063,7 @@ func (c *cmdConfigUefiSet) run(cmd *cobra.Command, args []string) error {

resource := resources[0]
if resource.name == "" {
return fmt.Errorf(i18n.G("Instance name must be specified"))
return errors.New(i18n.G("Instance name must be specified"))
}

// Set the config keys
Expand Down Expand Up @@ -1181,7 +1182,7 @@ func (c *cmdConfigUefiShow) run(cmd *cobra.Command, args []string) error {

resource := resources[0]
if resource.name == "" {
return fmt.Errorf(i18n.G("Instance name must be specified"))
return errors.New(i18n.G("Instance name must be specified"))
}

instEFI, _, err := resource.server.GetInstanceUEFIVars(resource.name)
Expand Down Expand Up @@ -1273,7 +1274,7 @@ func (c *cmdConfigUefiEdit) run(cmd *cobra.Command, args []string) error {

resource := resources[0]
if resource.name == "" {
return fmt.Errorf(i18n.G("Instance name must be specified"))
return errors.New(i18n.G("Instance name must be specified"))
}

// If stdin isn't a terminal, read text from it
Expand Down
5 changes: 3 additions & 2 deletions lxc/config_metadata.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -108,7 +109,7 @@ func (c *cmdConfigMetadataEdit) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing instance name"))
return errors.New(i18n.G("Missing instance name"))
}

// Edit the metadata
Expand Down Expand Up @@ -217,7 +218,7 @@ func (c *cmdConfigMetadataShow) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing instance name"))
return errors.New(i18n.G("Missing instance name"))
}

// Show the instance metadata
Expand Down
11 changes: 6 additions & 5 deletions lxc/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (c *cmdConfigTemplateCreate) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing instance name"))
return errors.New(i18n.G("Missing instance name"))
}

// Create instance file template
Expand Down Expand Up @@ -151,7 +152,7 @@ func (c *cmdConfigTemplateDelete) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing instance name"))
return errors.New(i18n.G("Missing instance name"))
}

// Delete instance file template
Expand Down Expand Up @@ -205,7 +206,7 @@ func (c *cmdConfigTemplateEdit) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing instance name"))
return errors.New(i18n.G("Missing instance name"))
}

// Edit instance file template
Expand Down Expand Up @@ -302,7 +303,7 @@ func (c *cmdConfigTemplateList) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing instance name"))
return errors.New(i18n.G("Missing instance name"))
}

// List the templates
Expand Down Expand Up @@ -373,7 +374,7 @@ func (c *cmdConfigTemplateShow) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

if resource.name == "" {
return fmt.Errorf(i18n.G("Missing instance name"))
return errors.New(i18n.G("Missing instance name"))
}

// Show the template
Expand Down
13 changes: 7 additions & 6 deletions lxc/copy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -94,12 +95,12 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR

// Make sure we have an instance or snapshot name
if sourceName == "" {
return fmt.Errorf(i18n.G("You must specify a source instance name"))
return errors.New(i18n.G("You must specify a source instance name"))
}

// Don't allow refreshing without profiles.
if c.flagRefresh && c.flagNoProfiles {
return fmt.Errorf(i18n.G("--no-profiles cannot be used with --refresh"))
return errors.New(i18n.G("--no-profiles cannot be used with --refresh"))
}

// If the instance is being copied to a different remote and no destination name is
Expand All @@ -111,7 +112,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR

// Ensure that a destination name is provided.
if destName == "" {
return fmt.Errorf(i18n.G("You must specify a destination instance name"))
return errors.New(i18n.G("You must specify a destination instance name"))
}

// Connect to the source host
Expand Down Expand Up @@ -140,7 +141,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR

// Confirm that --target is only used with a cluster
if c.flagTarget != "" && !dest.IsClustered() {
return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster"))
return errors.New(i18n.G("To use --target, the destination remote must be a cluster"))
}

// Parse the config overrides
Expand All @@ -165,7 +166,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR

if shared.IsSnapshot(sourceName) {
if instanceOnly {
return fmt.Errorf(i18n.G("--instance-only can't be passed when the source is a snapshot"))
return errors.New(i18n.G("--instance-only can't be passed when the source is a snapshot"))
}

// Prepare the instance creation request
Expand All @@ -176,7 +177,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR
}

if c.flagRefresh {
return fmt.Errorf(i18n.G("--refresh can only be used with instances"))
return errors.New(i18n.G("--refresh can only be used with instances"))
}

// Copy of a snapshot into a new instance
Expand Down
5 changes: 3 additions & 2 deletions lxc/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (c *cmdDelete) promptDelete(name string) error {
input = strings.TrimSuffix(input, "\n")

if !shared.ValueInSlice(strings.ToLower(input), []string{i18n.G("yes")}) {
return fmt.Errorf(i18n.G("User aborted delete operation"))
return errors.New(i18n.G("User aborted delete operation"))
}

return nil
Expand Down Expand Up @@ -124,7 +125,7 @@ func (c *cmdDelete) run(cmd *cobra.Command, args []string) error {

if ct.StatusCode != 0 && ct.StatusCode != api.Stopped {
if !c.flagForce {
return fmt.Errorf(i18n.G("The instance is currently running, stop it first or pass --force"))
return errors.New(i18n.G("The instance is currently running, stop it first or pass --force"))
}

req := api.InstanceStatePut{
Expand Down
Loading

0 comments on commit 40bae5c

Please sign in to comment.