Skip to content

Commit 93e006c

Browse files
authored
Fix deferInLoop error (#10387)
Signed-off-by: z1cheng <[email protected]>
1 parent fb7f92a commit 93e006c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

internal/nginx/maxmind.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,19 @@ func downloadDatabase(dbName string) error {
179179
if !strings.HasSuffix(header.Name, mmdbFile) {
180180
continue
181181
}
182+
return func() error {
183+
outFile, err := os.Create(path.Join(geoIPPath, mmdbFile))
184+
if err != nil {
185+
return err
186+
}
182187

183-
outFile, err := os.Create(path.Join(geoIPPath, mmdbFile))
184-
if err != nil {
185-
return err
186-
}
187-
188-
//nolint:gocritic // TODO: will fix it on a followup PR
189-
defer outFile.Close()
190-
191-
if _, err := io.CopyN(outFile, tarReader, header.Size); err != nil {
192-
return err
193-
}
188+
defer outFile.Close()
194189

195-
return nil
190+
if _, err := io.CopyN(outFile, tarReader, header.Size); err != nil {
191+
return err
192+
}
193+
return nil
194+
}()
196195
}
197196
}
198197

0 commit comments

Comments
 (0)