Exclude list

The private function will decrease the wait group counter before it finishes using the Done method.. Besides that, the first thing it should do is check the filename so that it can skip it if it is in the exclusion list:

defer wg.Done()
_, name := filepath.Split(file)
if o != nil {
for _, e := range o.Exclude {
if e == name {
return
}
}
}

If that is not the case, we can check the current file's information using os.Stat and send an error to the channel if we don't succeed. Since we cannot risk causing a panic by sending into a closed channel, we can check whether the context is done, and if not, send the error:

info, err := os.Stat(file)
if err != nil {
select {
case <-ctx.Done():
return
default:
ch <- Result{File: file, Err: err}
}
return
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.46.58