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 3, 2024
1 parent 684974b commit 2c1950e
Show file tree
Hide file tree
Showing 30 changed files with 365 additions and 337 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
21 changes: 11 additions & 10 deletions lxc/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -163,7 +164,7 @@ func (c *cmdClusterList) run(cmd *cobra.Command, args []string) error {
}

if !cluster.Enabled {
return fmt.Errorf(i18n.G("LXD server isn't part of a cluster"))
return errors.New(i18n.G("LXD server isn't part of a cluster"))
}

// Get the cluster members
Expand Down Expand Up @@ -621,7 +622,7 @@ Are you really sure you want to force removing %s? (yes/no): `), name)
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 @@ -725,7 +726,7 @@ func (c *cmdClusterEnable) run(cmd *cobra.Command, args []string) error {
}

if server.Config["core.https_address"] == "" && server.Config["cluster.https_address"] == "" {
return fmt.Errorf(i18n.G("This LXD server is not available on the network"))
return errors.New(i18n.G("This LXD server is not available on the network"))
}

// Check if already enabled
Expand All @@ -735,7 +736,7 @@ func (c *cmdClusterEnable) run(cmd *cobra.Command, args []string) error {
}

if currentCluster.Enabled {
return fmt.Errorf(i18n.G("This LXD server is already clustered"))
return errors.New(i18n.G("This LXD server is already clustered"))
}

// Enable clustering.
Expand Down Expand Up @@ -807,7 +808,7 @@ func (c *cmdClusterEdit) 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"))
}

// If stdin isn't a terminal, read text from it
Expand Down Expand Up @@ -922,7 +923,7 @@ func (c *cmdClusterAdd) run(cmd *cobra.Command, args []string) error {

// Determine the machine name.
if resource.name != "" && c.flagName != "" && resource.name != c.flagName {
return fmt.Errorf(i18n.G("Cluster member name was provided as both a flag and as an argument"))
return errors.New(i18n.G("Cluster member name was provided as both a flag and as an argument"))
}

if resource.name == "" {
Expand Down Expand Up @@ -1016,7 +1017,7 @@ func (c *cmdClusterListTokens) run(cmd *cobra.Command, args []string) error {
}

if !cluster.Enabled {
return fmt.Errorf(i18n.G("LXD server isn't part of a cluster"))
return errors.New(i18n.G("LXD server isn't part of a cluster"))
}

// Get the cluster member join tokens. Use default project as join tokens are created in default project.
Expand Down Expand Up @@ -1119,7 +1120,7 @@ func (c *cmdClusterRevokeToken) run(cmd *cobra.Command, args []string) error {
}

if !cluster.Enabled {
return fmt.Errorf(i18n.G("LXD server isn't part of a cluster"))
return errors.New(i18n.G("LXD server isn't part of a cluster"))
}

// Get the cluster member join tokens. Use default project as join tokens are created in default project.
Expand Down Expand Up @@ -1227,7 +1228,7 @@ func (c *cmdClusterUpdateCertificate) run(cmd *cobra.Command, args []string) err
}

if !cluster.Enabled {
return fmt.Errorf(i18n.G("LXD server isn't part of a cluster"))
return errors.New(i18n.G("LXD server isn't part of a cluster"))
}

if !shared.PathExists(certFile) {
Expand Down Expand Up @@ -1363,7 +1364,7 @@ func (c *cmdClusterEvacuateAction) 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"))
}

if !c.flagForce {
Expand Down
17 changes: 9 additions & 8 deletions lxc/cluster_group.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 @@ -125,7 +126,7 @@ func (c *cmdClusterGroupAssign) run(cmd *cobra.Command, args []string) error {

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

member, etag, err := resource.server.GetClusterMember(resource.name)
Expand Down Expand Up @@ -199,7 +200,7 @@ func (c *cmdClusterGroupCreate) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

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

// Create the cluster group
Expand Down Expand Up @@ -264,7 +265,7 @@ func (c *cmdClusterGroupDelete) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

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

// Delete the cluster group
Expand Down Expand Up @@ -324,7 +325,7 @@ func (c *cmdClusterGroupEdit) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

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

// If stdin isn't a terminal, read text from it
Expand Down Expand Up @@ -460,7 +461,7 @@ func (c *cmdClusterGroupList) run(cmd *cobra.Command, args []string) error {
}

if !cluster.Enabled {
return fmt.Errorf(i18n.G("LXD server isn't part of a cluster"))
return errors.New(i18n.G("LXD server isn't part of a cluster"))
}

groups, err := resource.server.GetClusterGroups()
Expand Down Expand Up @@ -534,7 +535,7 @@ func (c *cmdClusterGroupRemove) 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"))
}

// Remove the cluster group
Expand Down Expand Up @@ -671,7 +672,7 @@ func (c *cmdClusterGroupShow) run(cmd *cobra.Command, args []string) error {
resource := resources[0]

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

// Show the cluster group
Expand Down Expand Up @@ -736,7 +737,7 @@ func (c *cmdClusterGroupAdd) 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"))
}

// Retrieve cluster member information.
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
Loading

0 comments on commit 2c1950e

Please sign in to comment.