From 484dbb1cf49d6348ff0d35e0bf88126e851e63ba Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 30 Mar 2024 14:28:59 +0100 Subject: [PATCH] get rid of a few global variables --- cmd/restic/global.go | 2 +- cmd/restic/main.go | 3 +-- helpers/prepare-release/main.go | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 5b21871dc..40083ad69 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -43,7 +43,7 @@ import ( "golang.org/x/term" ) -var version = "0.16.4-dev (compiled manually)" +const version = "0.16.4-dev (compiled manually)" // TimeFormat is the format used for all timestamps printed by restic. const TimeFormat = "2006-01-02 15:04:05" diff --git a/cmd/restic/main.go b/cmd/restic/main.go index 82517c31a..e847b8156 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -94,8 +94,6 @@ func needsPassword(cmd string) bool { } } -var logBuffer = bytes.NewBuffer(nil) - func tweakGoGC() { // lower GOGC from 100 to 50, unless it was manually overwritten by the user oldValue := godebug.SetGCPercent(50) @@ -108,6 +106,7 @@ func main() { tweakGoGC() // install custom global logger into a buffer, if an error occurs // we can show the logs + logBuffer := bytes.NewBuffer(nil) log.SetOutput(logBuffer) err := feature.Flag.Apply(os.Getenv("RESTIC_FEATURES"), func(s string) { diff --git a/helpers/prepare-release/main.go b/helpers/prepare-release/main.go index baf8aa2ba..703d85e70 100644 --- a/helpers/prepare-release/main.go +++ b/helpers/prepare-release/main.go @@ -303,7 +303,7 @@ func generateFiles() { } } -var versionPattern = `var version = ".*"` +var versionPattern = `const version = ".*"` const versionCodeFile = "cmd/restic/global.go" @@ -313,7 +313,7 @@ func updateVersion() { die("unable to write version to file: %v", err) } - newVersion := fmt.Sprintf("var version = %q", opts.Version) + newVersion := fmt.Sprintf("const version = %q", opts.Version) replace(versionCodeFile, versionPattern, newVersion) if len(uncommittedChanges("VERSION")) > 0 || len(uncommittedChanges(versionCodeFile)) > 0 { @@ -323,7 +323,7 @@ func updateVersion() { } func updateVersionDev() { - newVersion := fmt.Sprintf(`var version = "%s-dev (compiled manually)"`, opts.Version) + newVersion := fmt.Sprintf(`const version = "%s-dev (compiled manually)"`, opts.Version) replace(versionCodeFile, versionPattern, newVersion) msg("committing cmd/restic/global.go with dev version")