Skip to content

Commit

Permalink
Fixed a goroutine leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihonarium authored Feb 1, 2021
1 parent e166576 commit 75ff09e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/scanFiles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func RecognizeMultipleFiles(dir string, client *audd.Client, setID3, short bool,
cover = "https://i3.ytimg.com/vi/"+strings.ReplaceAll(result[i].SongLink, "https://youtu.be/", "")+"/maxresdefault.jpg"
}
response, err := http.Get(cover)
defer closeBody(response)
if err != nil {
fmt.Println("Error: can't get the cover for", fileName, err)
} else {
Expand Down Expand Up @@ -198,6 +199,16 @@ func getCurrentDir() string {
return filepath.Dir(currentFile)
}

func closeBody(resp *http.Response) {
if resp == nil {
return
}
if resp.Body == nil {
return
}
_ = resp.Body.Close()
}

func main() {
dir := flag.String("dir", getCurrentDir(), "The directory with the files")
apiToken := flag.String("api_token", "test", "AudD API token")
Expand Down

0 comments on commit 75ff09e

Please sign in to comment.