diff --git a/cmd/check_imap_mailbox_basic/main.go b/cmd/check_imap_mailbox_basic/main.go index 3f4e0eb3..a3d253a2 100644 --- a/cmd/check_imap_mailbox_basic/main.go +++ b/cmd/check_imap_mailbox_basic/main.go @@ -70,6 +70,13 @@ func main() { // sufficient work is in place to allow bulk processing if there is // sufficient interest. for i, account := range cfg.Accounts { + // Building with `go build -gcflags=all=-d=loopvar=2` identified this + // loop as compiling differently with Go 1.22 (per-iteration) loop + // semantics. + // + // As a workaround, we create a new variable for each iteration to + // work around potential issues with Go versions prior to Go 1.22. + account := account logger := cfg.Log.With(). Str("username", account.Username). diff --git a/cmd/check_imap_mailbox_basic/summary.go b/cmd/check_imap_mailbox_basic/summary.go index ad30052b..fa468271 100644 --- a/cmd/check_imap_mailbox_basic/summary.go +++ b/cmd/check_imap_mailbox_basic/summary.go @@ -37,6 +37,14 @@ func setSummary(accounts []config.MailAccount, nes *nagios.Plugin) { ) for _, account := range accounts { + // Building with `go build -gcflags=all=-d=loopvar=2` identified this + // loop as compiling differently with Go 1.22 (per-iteration) loop + // semantics. + // + // As a workaround, we create a new variable for each iteration to + // work around potential issues with Go versions prior to Go 1.22. + account := account + accountSummary := fmt.Sprintf( "* Account: %s%s** Folders: %s%s%s", account.Username, diff --git a/cmd/check_imap_mailbox_oauth2/main.go b/cmd/check_imap_mailbox_oauth2/main.go index 852eaa33..6914ad64 100644 --- a/cmd/check_imap_mailbox_oauth2/main.go +++ b/cmd/check_imap_mailbox_oauth2/main.go @@ -71,6 +71,13 @@ func main() { // sufficient work is in place to allow bulk processing if there is // sufficient interest. for i, account := range cfg.Accounts { + // Building with `go build -gcflags=all=-d=loopvar=2` identified this + // loop as compiling differently with Go 1.22 (per-iteration) loop + // semantics. + // + // As a workaround, we create a new variable for each iteration to + // work around potential issues with Go versions prior to Go 1.22. + account := account logger := cfg.Log.With(). Str("client_id", account.OAuth2Settings.ClientID). diff --git a/cmd/check_imap_mailbox_oauth2/summary.go b/cmd/check_imap_mailbox_oauth2/summary.go index ad30052b..fa468271 100644 --- a/cmd/check_imap_mailbox_oauth2/summary.go +++ b/cmd/check_imap_mailbox_oauth2/summary.go @@ -37,6 +37,14 @@ func setSummary(accounts []config.MailAccount, nes *nagios.Plugin) { ) for _, account := range accounts { + // Building with `go build -gcflags=all=-d=loopvar=2` identified this + // loop as compiling differently with Go 1.22 (per-iteration) loop + // semantics. + // + // As a workaround, we create a new variable for each iteration to + // work around potential issues with Go versions prior to Go 1.22. + account := account + accountSummary := fmt.Sprintf( "* Account: %s%s** Folders: %s%s%s", account.Username, diff --git a/cmd/list-emails/main.go b/cmd/list-emails/main.go index 614f6ae2..732e4a49 100644 --- a/cmd/list-emails/main.go +++ b/cmd/list-emails/main.go @@ -88,6 +88,13 @@ func main() { // loop over accounts for i, account := range cfg.Accounts { + // Building with `go build -gcflags=all=-d=loopvar=2` identified this + // loop as compiling differently with Go 1.22 (per-iteration) loop + // semantics. + // + // As a workaround, we create a new variable for each iteration to + // work around potential issues with Go versions prior to Go 1.22. + account := account fmt.Println("Checking account:", account.Name) diff --git a/internal/config/file.go b/internal/config/file.go index f1025f94..81f4ce28 100644 --- a/internal/config/file.go +++ b/internal/config/file.go @@ -30,6 +30,14 @@ func (c *Config) readConfigFile(configFile ...string) ([]byte, error) { var finalErr error for _, file := range configFile { + // Building with `go build -gcflags=all=-d=loopvar=2` identified this + // loop as compiling differently with Go 1.22 (per-iteration) loop + // semantics. + // + // As a workaround, we create a new variable for each iteration to + // work around potential issues with Go versions prior to Go 1.22. + file := file + c.Log.Debug().Str("config_file", file).Msg("Attempting to open config file") fh, err := os.Open(filepath.Clean(file))