Skip to content

Commit

Permalink
Merge pull request #642 from atc0005/fix-loopvar-behavior-change-lint…
Browse files Browse the repository at this point in the history
…ing-error

Fix loopvar behavior change linting error
  • Loading branch information
atc0005 authored Mar 1, 2024
2 parents 0d76d18 + 9dcc84c commit 32c6ea4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/check_imap_mailbox_basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 8 additions & 0 deletions cmd/check_imap_mailbox_basic/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions cmd/check_imap_mailbox_oauth2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 8 additions & 0 deletions cmd/check_imap_mailbox_oauth2/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions cmd/list-emails/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions internal/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 32c6ea4

Please sign in to comment.