func NewWatcher(session *sharesession.Session, watchedDir string) (w *Watcher, err error) { w = &Watcher{ session: session, watchedDir: watchedDir, PingNewTorrent: make(chan string), } go w.watch() // Initialization, only if there is something in the dir if _, err := os.Stat(watchedDir); err != nil { return nil, err } st, err := os.Stat(watchedDir) if err != nil { return nil, err } if !st.IsDir() { return nil, errInvalidDir } go func() { w.PingNewTorrent <- session.GetCurrentInfohash() }() return }