[lxc-devel] [lxd/master] simplestreams.go: remove unneeded fmt.Sprintf and simplify getImages()

TimRots on Github lxc-bot at linuxcontainers.org
Wed Oct 14 23:17:03 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 520 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201014/68752664/attachment.bin>
-------------- next part --------------
From b86ec451a5eda61ad35c52825fb826a4bb76966f Mon Sep 17 00:00:00 2001
From: Tim Rots <tim.rots at protonmail.ch>
Date: Thu, 15 Oct 2020 01:06:28 +0200
Subject: [PATCH] simplestreams.go: remove unneeded fmt.Sprintf and simplify
 getImages()

* use time.Since() instead of time.Now().Sub() for readbility
* entry.Name is already string type, no need for fmt.Sprintf
* remove unneeded for-loop in getImages()

Signed-off-by: Tim Rots <tim.rots at protonmail.ch>
---
 shared/simplestreams/simplestreams.go | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/shared/simplestreams/simplestreams.go b/shared/simplestreams/simplestreams.go
index fd420326a3..4d623f6eb2 100644
--- a/shared/simplestreams/simplestreams.go
+++ b/shared/simplestreams/simplestreams.go
@@ -82,7 +82,7 @@ func (s *SimpleStreams) readCache(path string) ([]byte, bool) {
 		return nil, false
 	}
 
-	expired := time.Now().Sub(fi.ModTime()) > s.cacheExpiry
+	expired := time.Since(fi.ModTime()) > s.cacheExpiry
 
 	return body, expired
 }
@@ -248,7 +248,7 @@ func (s *SimpleStreams) applyAliases(images []api.Image) ([]api.Image, []extende
 
 			for _, entry := range aliases {
 				// Short
-				alias := addAlias(image.Type, image.Architecture, fmt.Sprintf("%s", entry.Name), image.Fingerprint)
+				alias := addAlias(image.Type, image.Architecture, entry.Name, image.Fingerprint)
 				if alias != nil && architectureName == image.Architecture {
 					image.Aliases = append(image.Aliases, *alias)
 				}
@@ -298,10 +298,7 @@ func (s *SimpleStreams) getImages() ([]api.Image, []extendedAlias, error) {
 		}
 
 		streamImages, _ := products.ToLXD()
-
-		for _, image := range streamImages {
-			images = append(images, image)
-		}
+		images = append(images, streamImages...)
 	}
 
 	// Setup the aliases


More information about the lxc-devel mailing list