From c8d12038b66b1a5a6e251118073e5d2994ffa076 Mon Sep 17 00:00:00 2001 From: Chris Darroch Date: Fri, 28 Jan 2022 19:38:01 -0800 Subject: [PATCH] commands/commands.go: use fmt to concat strings In the logPanicToWriter() method a "le" variable containing an OS-specific line ending string (e.g., "\n" on Unix/Linux) is prepended and appended to various strings using the string concatentation operator. However, all these instances occur within fmt.Fprint() and fmt.Fprintf() calls, so we can simply use those tools to perform the concatenations. These changes will reduce the changes needed in a subsequent commit when we make some of these strings translatable. --- commands/commands.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index ee515887..d4715cda 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -482,8 +482,8 @@ func logPanicToWriter(w io.Writer, loggedError error, le string) { gitV = "Error getting Git version: " + err.Error() } - fmt.Fprint(w, config.VersionDesc+le) - fmt.Fprint(w, gitV+le) + fmt.Fprint(w, config.VersionDesc, le) + fmt.Fprint(w, gitV, le) // log the command that was run fmt.Fprint(w, le) @@ -497,26 +497,26 @@ func logPanicToWriter(w io.Writer, loggedError error, le string) { w.Write(ErrorBuffer.Bytes()) fmt.Fprint(w, le) - fmt.Fprintf(w, "%+v"+le, loggedError) + fmt.Fprintf(w, "%+v%s", loggedError, le) for key, val := range errors.Context(err) { - fmt.Fprintf(w, "%s=%v"+le, key, val) + fmt.Fprintf(w, "%s=%v%s", key, val, le) } - fmt.Fprint(w, le+"Current time in UTC: "+le) - fmt.Fprint(w, time.Now().UTC().Format("2006-01-02 15:04:05")+le) + fmt.Fprint(w, le, "Current time in UTC:", le) + fmt.Fprint(w, time.Now().UTC().Format("2006-01-02 15:04:05"), le) - fmt.Fprint(w, le+"Environment:"+le) + fmt.Fprint(w, le, "Environment:", le) // log the environment for _, env := range lfs.Environ(cfg, getTransferManifest(), oldEnv) { - fmt.Fprint(w, env+le) + fmt.Fprint(w, env, le) } - fmt.Fprint(w, le+"Client IP addresses:"+le) + fmt.Fprint(w, le, "Client IP addresses:", le) for _, ip := range ipAddresses() { - fmt.Fprint(w, ip+le) + fmt.Fprint(w, ip, le) } }