[lxc-devel] [lxd/master] lxc/init.go: remove for-loop in create()

TimRots on Github lxc-bot at linuxcontainers.org
Fri Oct 16 11:51:11 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 391 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201016/4d395ddb/attachment.bin>
-------------- next part --------------
From 3bbb97ad0a6b5c25735e2394cea8944dcbdf64be Mon Sep 17 00:00:00 2001
From: Tim Rots <tim.rots at protonmail.ch>
Date: Fri, 16 Oct 2020 13:48:51 +0200
Subject: [PATCH] lxc/init.go: remove for-loop in create()

* remove unneeded for-loop in create()

Signed-off-by: Tim Rots <tim.rots at protonmail.ch>
---
 lxc/init.go | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/lxc/init.go b/lxc/init.go
index ab04aa9f72..51f0343d27 100644
--- a/lxc/init.go
+++ b/lxc/init.go
@@ -84,6 +84,7 @@ func (c *cmdInit) create(conf *config.Config, args []string) (lxd.InstanceServer
 	var stdinData api.InstancePut
 	var devicesMap map[string]map[string]string
 	var configMap map[string]string
+	var profiles []string
 
 	// If stdin isn't a terminal, read text from it
 	if !termios.IsTerminal(getStdinFd()) {
@@ -91,9 +92,7 @@ func (c *cmdInit) create(conf *config.Config, args []string) (lxd.InstanceServer
 		if err != nil {
 			return nil, "", err
 		}
-
-		err = yaml.Unmarshal(contents, &stdinData)
-		if err != nil {
+		if err = yaml.Unmarshal(contents, &stdinData); err != nil {
 			return nil, "", err
 		}
 	}
@@ -145,10 +144,7 @@ func (c *cmdInit) create(conf *config.Config, args []string) (lxd.InstanceServer
 		d = d.UseTarget(c.flagTarget)
 	}
 
-	profiles := []string{}
-	for _, p := range c.flagProfile {
-		profiles = append(profiles, p)
-	}
+	profiles = append(profiles, c.flagProfile...)
 
 	if !c.global.flagQuiet {
 		if name == "" {
@@ -292,14 +288,12 @@ func (c *cmdInit) create(conf *config.Config, args []string) (lxd.InstanceServer
 			Quiet:  c.global.flagQuiet,
 		}
 
-		_, err = op.AddHandler(progress.UpdateOp)
-		if err != nil {
+		if _, err = op.AddHandler(progress.UpdateOp); err != nil {
 			progress.Done("")
 			return nil, "", err
 		}
 
-		err = utils.CancelableWait(op, &progress)
-		if err != nil {
+		if err = utils.CancelableWait(op, &progress); err != nil {
 			progress.Done("")
 			return nil, "", err
 		}
@@ -320,8 +314,7 @@ func (c *cmdInit) create(conf *config.Config, args []string) (lxd.InstanceServer
 			return nil, "", err
 		}
 
-		err = op.Wait()
-		if err != nil {
+		if err = op.Wait(); err != nil {
 			return nil, "", err
 		}
 


More information about the lxc-devel mailing list