Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loopvar behavior change linting error #642

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading