[lxc-devel] [lxd/master] shared/util.go: use string method with stdout and stderr

TimRots on Github lxc-bot at linuxcontainers.org
Wed Oct 14 22:24:11 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 375 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201014/01ebfe28/attachment.bin>
-------------- next part --------------
From 17b76d350d2cdbbae294ee1d8fe14332b43dd414 Mon Sep 17 00:00:00 2001
From: Tim Rots <tim.rots at protonmail.ch>
Date: Thu, 15 Oct 2020 00:14:21 +0200
Subject: [PATCH] shared/util.go: use string method with stdout and stderr

some small changes:
* use String() method with stdout and stderr
* simplified IsTrue function
---
 shared/util.go | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/shared/util.go b/shared/util.go
index 8b5bb9f4db..ed0bc08553 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -649,11 +649,7 @@ func Uint64InSlice(key uint64, list []uint64) bool {
 }
 
 func IsTrue(value string) bool {
-	if StringInSlice(strings.ToLower(value), []string{"true", "1", "yes", "on"}) {
-		return true
-	}
-
-	return false
+	return StringInSlice(strings.ToLower(value), []string{"true", "1", "yes", "on"})
 }
 
 // StringMapHasStringKey returns true if any of the supplied keys are present in the map.
@@ -898,15 +894,15 @@ func RunCommandSplit(env []string, filesInherit []*os.File, name string, arg ...
 	err := cmd.Run()
 	if err != nil {
 		err := RunError{
-			msg:    fmt.Sprintf("Failed to run: %s %s: %s", name, strings.Join(arg, " "), strings.TrimSpace(string(stderr.Bytes()))),
-			Stdout: string(stdout.Bytes()),
-			Stderr: string(stderr.Bytes()),
+			msg:    fmt.Sprintf("Failed to run: %s %s: %s", name, strings.Join(arg, " "), strings.TrimSpace(stderr.String())),
+			Stdout: stdout.String(),
+			Stderr: stderr.String(),
 			Err:    err,
 		}
-		return string(stdout.Bytes()), string(stderr.Bytes()), err
+		return stdout.String(), stderr.String(), err
 	}
 
-	return string(stdout.Bytes()), string(stderr.Bytes()), nil
+	return stdout.String(), stderr.String(), nil
 }
 
 // RunCommand runs a command with optional arguments and returns stdout. If the command fails to


More information about the lxc-devel mailing list