[lxc-devel] [lxd/master] Go tool vet lxc/*.

pcdummy on Github lxc-bot at linuxcontainers.org
Wed Feb 24 23:02:52 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 345 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160224/4a202aac/attachment.bin>
-------------- next part --------------
From a8cb69735dafbd4468cc731c81ac6e27d02553fa Mon Sep 17 00:00:00 2001
From: Rene Jochum <rene at jochums.at>
Date: Thu, 25 Feb 2016 00:02:04 +0100
Subject: [PATCH] Go tool vet lxc/*.

Signed-off-by: Rene Jochum <rene at jochums.at>
---
 lxc/copy.go   | 116 +++++++++++++++++++++++++++++-----------------------------
 lxc/list.go   |  38 +++++++++----------
 lxc/remote.go |  58 ++++++++++++++---------------
 3 files changed, 106 insertions(+), 106 deletions(-)

diff --git a/lxc/copy.go b/lxc/copy.go
index 39e4651..a451919 100644
--- a/lxc/copy.go
+++ b/lxc/copy.go
@@ -84,82 +84,82 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR
 		}
 
 		return source.WaitForSuccess(cp.Operation)
-	} else {
-		dest, err := lxd.NewClient(config, destRemote)
-		if err != nil {
-			return err
-		}
+	}
+
+	dest, err := lxd.NewClient(config, destRemote)
+	if err != nil {
+		return err
+	}
+
+	sourceProfs := shared.NewStringSet(status.Profiles)
+	destProfs, err := dest.ListProfiles()
+	if err != nil {
+		return err
+	}
+
+	if !sourceProfs.IsSubset(shared.NewStringSet(destProfs)) {
+		return fmt.Errorf(i18n.G("not all the profiles from the source exist on the target"))
+	}
 
-		sourceProfs := shared.NewStringSet(status.Profiles)
-		destProfs, err := dest.ListProfiles()
+	if ephemeral == -1 {
+		ct, err := source.ContainerInfo(sourceName)
 		if err != nil {
 			return err
 		}
 
-		if !sourceProfs.IsSubset(shared.NewStringSet(destProfs)) {
-			return fmt.Errorf(i18n.G("not all the profiles from the source exist on the target"))
+		if ct.Ephemeral {
+			ephemeral = 1
+		} else {
+			ephemeral = 0
 		}
+	}
 
-		if ephemeral == -1 {
-			ct, err := source.ContainerInfo(sourceName)
-			if err != nil {
-				return err
-			}
-
-			if ct.Ephemeral {
-				ephemeral = 1
-			} else {
-				ephemeral = 0
-			}
-		}
+	sourceWSResponse, err := source.GetMigrationSourceWS(sourceName)
+	if err != nil {
+		return err
+	}
 
-		sourceWSResponse, err := source.GetMigrationSourceWS(sourceName)
-		if err != nil {
-			return err
-		}
+	secrets := map[string]string{}
 
-		secrets := map[string]string{}
+	op, err := sourceWSResponse.MetadataAsOperation()
+	if err != nil {
+		return err
+	}
 
-		op, err := sourceWSResponse.MetadataAsOperation()
-		if err != nil {
-			return err
-		}
+	for k, v := range *op.Metadata {
+		secrets[k] = v.(string)
+	}
 
-		for k, v := range *op.Metadata {
-			secrets[k] = v.(string)
-		}
+	addresses, err := source.Addresses()
+	if err != nil {
+		return err
+	}
 
-		addresses, err := source.Addresses()
+	/* Since we're trying a bunch of different network ports that
+	 * may be invalid, we can get "bad handshake" errors when the
+	 * websocket code tries to connect. If the first error is a
+	 * real error, but the subsequent errors are only network
+	 * errors, we should try to report the first real error. Of
+	 * course, if all the errors are websocket errors, let's just
+	 * report that.
+	 */
+	for _, addr := range addresses {
+		var migration *lxd.Response
+
+		sourceWSUrl := "https://" + addr + sourceWSResponse.Operation
+		migration, err = dest.MigrateFrom(destName, sourceWSUrl, source.Certificate, secrets, status.Architecture, status.Config, status.Devices, status.Profiles, baseImage, ephemeral == 1)
 		if err != nil {
-			return err
+			continue
 		}
 
-		/* Since we're trying a bunch of different network ports that
-		 * may be invalid, we can get "bad handshake" errors when the
-		 * websocket code tries to connect. If the first error is a
-		 * real error, but the subsequent errors are only network
-		 * errors, we should try to report the first real error. Of
-		 * course, if all the errors are websocket errors, let's just
-		 * report that.
-		 */
-		for _, addr := range addresses {
-			var migration *lxd.Response
-
-			sourceWSUrl := "https://" + addr + sourceWSResponse.Operation
-			migration, err = dest.MigrateFrom(destName, sourceWSUrl, source.Certificate, secrets, status.Architecture, status.Config, status.Devices, status.Profiles, baseImage, ephemeral == 1)
-			if err != nil {
-				continue
-			}
-
-			if err = dest.WaitForSuccess(migration.Operation); err != nil {
-				return err
-			}
-
-			return nil
+		if err = dest.WaitForSuccess(migration.Operation); err != nil {
+			return err
 		}
 
-		return err
+		return nil
 	}
+
+	return err
 }
 
 func (c *copyCmd) run(config *lxd.Config, args []string) error {
diff --git a/lxc/list.go b/lxc/list.go
index 949222e..d120809 100644
--- a/lxc/list.go
+++ b/lxc/list.go
@@ -16,7 +16,7 @@ import (
 	"github.com/lxc/lxd/shared/i18n"
 )
 
-type Column struct {
+type column struct {
 	Name           string
 	Data           columnData
 	NeedsState     bool
@@ -25,17 +25,17 @@ type Column struct {
 
 type columnData func(shared.ContainerInfo, *shared.ContainerState, []shared.SnapshotInfo) string
 
-type ByName [][]string
+type byName [][]string
 
-func (a ByName) Len() int {
+func (a byName) Len() int {
 	return len(a)
 }
 
-func (a ByName) Swap(i, j int) {
+func (a byName) Swap(i, j int) {
 	a[i], a[j] = a[j], a[i]
 }
 
-func (a ByName) Less(i, j int) bool {
+func (a byName) Less(i, j int) bool {
 	if a[i][0] == "" {
 		return false
 	}
@@ -160,7 +160,7 @@ func (c *listCmd) shouldShow(filters []string, state *shared.ContainerInfo) bool
 	return true
 }
 
-func (c *listCmd) listContainers(d *lxd.Client, cinfos []shared.ContainerInfo, filters []string, columns []Column) error {
+func (c *listCmd) listContainers(d *lxd.Client, cinfos []shared.ContainerInfo, filters []string, columns []column) error {
 	headers := []string{}
 	for _, column := range columns {
 		headers = append(headers, column.Name)
@@ -279,7 +279,7 @@ func (c *listCmd) listContainers(d *lxd.Client, cinfos []shared.ContainerInfo, f
 	table.SetAutoWrapText(false)
 	table.SetRowLine(true)
 	table.SetHeader(headers)
-	sort.Sort(ByName(data))
+	sort.Sort(byName(data))
 	table.AppendBulk(data)
 	table.Render()
 
@@ -328,24 +328,24 @@ func (c *listCmd) run(config *lxd.Config, args []string) error {
 		}
 	}
 
-	columns_map := map[rune]Column{
-		'4': Column{i18n.G("IPV4"), c.IP4ColumnData, true, false},
-		'6': Column{i18n.G("IPV6"), c.IP6ColumnData, true, false},
-		'a': Column{i18n.G("ARCHITECTURE"), c.ArchitectureColumnData, false, false},
-		'c': Column{i18n.G("CREATED AT"), c.CreatedColumnData, false, false},
-		'n': Column{i18n.G("NAME"), c.nameColumnData, false, false},
-		'p': Column{i18n.G("PID"), c.PIDColumnData, true, false},
-		'P': Column{i18n.G("PROFILES"), c.ProfilesColumnData, false, false},
-		'S': Column{i18n.G("SNAPSHOTS"), c.numberSnapshotsColumnData, false, true},
-		's': Column{i18n.G("STATE"), c.statusColumnData, false, false},
-		't': Column{i18n.G("TYPE"), c.typeColumnData, false, false},
+	columns_map := map[rune]column{
+		'4': column{i18n.G("IPV4"), c.IP4ColumnData, true, false},
+		'6': column{i18n.G("IPV6"), c.IP6ColumnData, true, false},
+		'a': column{i18n.G("ARCHITECTURE"), c.ArchitectureColumnData, false, false},
+		'c': column{i18n.G("CREATED AT"), c.CreatedColumnData, false, false},
+		'n': column{i18n.G("NAME"), c.nameColumnData, false, false},
+		'p': column{i18n.G("PID"), c.PIDColumnData, true, false},
+		'P': column{i18n.G("PROFILES"), c.ProfilesColumnData, false, false},
+		'S': column{i18n.G("SNAPSHOTS"), c.numberSnapshotsColumnData, false, true},
+		's': column{i18n.G("STATE"), c.statusColumnData, false, false},
+		't': column{i18n.G("TYPE"), c.typeColumnData, false, false},
 	}
 
 	if c.fast {
 		c.chosenColumnRunes = "nsacPt"
 	}
 
-	columns := []Column{}
+	columns := []column{}
 	for _, columnRune := range c.chosenColumnRunes {
 		if column, ok := columns_map[columnRune]; ok {
 			columns = append(columns, column)
diff --git a/lxc/remote.go b/lxc/remote.go
index 37590dc..9588660 100644
--- a/lxc/remote.go
+++ b/lxc/remote.go
@@ -53,69 +53,69 @@ func (c *remoteCmd) flags() {
 }
 
 func (c *remoteCmd) addServer(config *lxd.Config, server string, addr string, acceptCert bool, password string, public bool) error {
-	var r_scheme string
-	var r_host string
-	var r_port string
+	var rScheme string
+	var rHost string
+	var rPort string
 
 	/* Complex remote URL parsing */
-	remote_url, err := url.Parse(addr)
+	remoteURL, err := url.Parse(addr)
 	if err != nil {
 		return err
 	}
 
-	if remote_url.Scheme != "" {
-		if remote_url.Scheme != "unix" && remote_url.Scheme != "https" {
-			r_scheme = "https"
+	if remoteURL.Scheme != "" {
+		if remoteURL.Scheme != "unix" && remoteURL.Scheme != "https" {
+			rScheme = "https"
 		} else {
-			r_scheme = remote_url.Scheme
+			rScheme = remoteURL.Scheme
 		}
 	} else if addr[0] == '/' {
-		r_scheme = "unix"
+		rScheme = "unix"
 	} else {
 		if !shared.PathExists(addr) {
-			r_scheme = "https"
+			rScheme = "https"
 		} else {
-			r_scheme = "unix"
+			rScheme = "unix"
 		}
 	}
 
-	if remote_url.Host != "" {
-		r_host = remote_url.Host
+	if remoteURL.Host != "" {
+		rHost = remoteURL.Host
 	} else {
-		r_host = addr
+		rHost = addr
 	}
 
-	host, port, err := net.SplitHostPort(r_host)
+	host, port, err := net.SplitHostPort(rHost)
 	if err == nil {
-		r_host = host
-		r_port = port
+		rHost = host
+		rPort = port
 	} else {
-		r_port = shared.DefaultPort
+		rPort = shared.DefaultPort
 	}
 
-	if r_scheme == "unix" {
+	if rScheme == "unix" {
 		if addr[0:5] == "unix:" {
 			if addr[0:7] == "unix://" {
 				if len(addr) > 8 {
-					r_host = addr[8:]
+					rHost = addr[8:]
 				} else {
-					r_host = ""
+					rHost = ""
 				}
 			} else {
-				r_host = addr[6:]
+				rHost = addr[6:]
 			}
 		}
-		r_port = ""
+		rPort = ""
 	}
 
-	if strings.Contains(r_host, ":") && !strings.HasPrefix(r_host, "[") {
-		r_host = fmt.Sprintf("[%s]", r_host)
+	if strings.Contains(rHost, ":") && !strings.HasPrefix(rHost, "[") {
+		rHost = fmt.Sprintf("[%s]", rHost)
 	}
 
-	if r_port != "" {
-		addr = r_scheme + "://" + r_host + ":" + r_port
+	if rPort != "" {
+		addr = rScheme + "://" + rHost + ":" + rPort
 	} else {
-		addr = r_scheme + "://" + r_host
+		addr = rScheme + "://" + rHost
 	}
 
 	if config.Remotes == nil {
@@ -296,7 +296,7 @@ func (c *remoteCmd) run(config *lxd.Config, args []string) error {
 			i18n.G("NAME"),
 			i18n.G("URL"),
 			i18n.G("PUBLIC")})
-		sort.Sort(ByName(data))
+		sort.Sort(byName(data))
 		table.AppendBulk(data)
 		table.Render()
 


More information about the lxc-devel mailing list