diff --git a/os/gfsnotify/gfsnotify.go b/os/gfsnotify/gfsnotify.go index 0224b8ba0..9c2f5864f 100644 --- a/os/gfsnotify/gfsnotify.go +++ b/os/gfsnotify/gfsnotify.go @@ -96,8 +96,8 @@ func New() (*Watcher, error) { return w, nil } -// Add monitors using default watcher with callback function . -// The optional parameter specifies whether monitoring the recursively, which is true in default. +// Add monitors `path` using default watcher with callback function `callbackFunc`. +// The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default. func Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) { w, err := getDefaultWatcher() if err != nil { @@ -106,11 +106,11 @@ func Add(path string, callbackFunc func(event *Event), recursive ...bool) (callb return w.Add(path, callbackFunc, recursive...) } -// AddOnce monitors using default watcher with callback function only once using unique name . -// If AddOnce is called multiple times with the same parameter, is only added to monitor once. It returns error -// if it's called twice with the same . +// AddOnce monitors `path` using default watcher with callback function `callbackFunc` only once using unique name `name`. +// If AddOnce is called multiple times with the same `name` parameter, `path` is only added to monitor once. It returns error +// if it's called twice with the same `name`. // -// The optional parameter specifies whether monitoring the recursively, which is true in default. +// The optional parameter `recursive` specifies whether monitoring the `path` recursively, which is true in default. func AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) { w, err := getDefaultWatcher() if err != nil { @@ -119,7 +119,7 @@ func AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bo return w.AddOnce(name, path, callbackFunc, recursive...) } -// Remove removes all monitoring callbacks of given from watcher recursively. +// Remove removes all monitoring callbacks of given `path` from watcher recursively. func Remove(path string) error { w, err := getDefaultWatcher() if err != nil { diff --git a/os/gfsnotify/gfsnotify_filefunc.go b/os/gfsnotify/gfsnotify_filefunc.go index f1d4daef6..3be6fbde8 100644 --- a/os/gfsnotify/gfsnotify_filefunc.go +++ b/os/gfsnotify/gfsnotify_filefunc.go @@ -24,7 +24,7 @@ func fileDir(path string) string { return filepath.Dir(path) } -// fileRealPath converts the given to its absolute path +// fileRealPath converts the given `path` to its absolute path // and checks if the file path exists. // If the file does not exist, return an empty string. func fileRealPath(path string) string { @@ -38,7 +38,7 @@ func fileRealPath(path string) string { return p } -// fileExists checks whether given exist. +// fileExists checks whether given `path` exist. func fileExists(path string) bool { if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) { return true @@ -46,7 +46,7 @@ func fileExists(path string) bool { return false } -// fileIsDir checks whether given a directory. +// fileIsDir checks whether given `path` a directory. func fileIsDir(path string) bool { s, err := os.Stat(path) if err != nil { @@ -55,7 +55,7 @@ func fileIsDir(path string) bool { return s.IsDir() } -// fileAllDirs returns all sub-folders including itself of given recursively. +// fileAllDirs returns all sub-folders including itself of given `path` recursively. func fileAllDirs(path string) (list []string) { list = []string{path} file, err := os.Open(path) @@ -78,8 +78,8 @@ func fileAllDirs(path string) (list []string) { return } -// fileScanDir returns all sub-files with absolute paths of given , -// It scans directory recursively if given parameter is true. +// fileScanDir returns all sub-files with absolute paths of given `path`, +// It scans directory recursively if given parameter `recursive` is true. func fileScanDir(path string, pattern string, recursive ...bool) ([]string, error) { list, err := doFileScanDir(path, pattern, recursive...) if err != nil { @@ -94,10 +94,10 @@ func fileScanDir(path string, pattern string, recursive ...bool) ([]string, erro // doFileScanDir is an internal method which scans directory // and returns the absolute path list of files that are not sorted. // -// The pattern parameter supports multiple file name patterns, +// The pattern parameter `pattern` supports multiple file name patterns, // using the ',' symbol to separate multiple patterns. // -// It scans directory recursively if given parameter is true. +// It scans directory recursively if given parameter `recursive` is true. func doFileScanDir(path string, pattern string, recursive ...bool) ([]string, error) { list := ([]string)(nil) file, err := os.Open(path) diff --git a/os/gfsnotify/gfsnotify_watcher.go b/os/gfsnotify/gfsnotify_watcher.go index 3219c26c8..777ada43a 100644 --- a/os/gfsnotify/gfsnotify_watcher.go +++ b/os/gfsnotify/gfsnotify_watcher.go @@ -14,19 +14,20 @@ import ( "github.com/gogf/gf/container/glist" ) -// Add monitors with callback function to the watcher. -// The optional parameter specifies whether monitoring the recursively, +// Add monitors `path` with callback function `callbackFunc` to the watcher. +// The optional parameter `recursive` specifies whether monitoring the `path` recursively, // which is true in default. func (w *Watcher) Add(path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) { return w.AddOnce("", path, callbackFunc, recursive...) } -// AddOnce monitors with callback function only once using unique name -// to the watcher. If AddOnce is called multiple times with the same parameter, -// is only added to monitor once. -// It returns error if it's called twice with the same . +// AddOnce monitors `path` with callback function `callbackFunc` only once using unique name +// `name` to the watcher. If AddOnce is called multiple times with the same `name` parameter, +// `path` is only added to monitor once. // -// The optional parameter specifies whether monitoring the recursively, +// It returns error if it's called twice with the same `name`. +// +// The optional parameter `recursive` specifies whether monitoring the `path` recursively, // which is true in default. func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) { w.nameSet.AddIfNotExistFuncLock(name, func() bool { @@ -99,8 +100,6 @@ func (w *Watcher) addWithCallbackFunc(name, path string, callbackFunc func(event } // Add the callback to global callback map. callbackIdMap.Set(callback.Id, callback) - - //intlog.Print("addWithCallbackFunc", name, path, callback.recursive) return } @@ -113,7 +112,7 @@ func (w *Watcher) Close() { close(w.closeChan) } -// Remove removes monitor and all callbacks associated with the recursively. +// Remove removes monitor and all callbacks associated with the `path` recursively. func (w *Watcher) Remove(path string) error { // Firstly remove the callbacks of the path. if r := w.callbacks.Remove(path); r != nil { diff --git a/os/gfsnotify/gfsnotify_watcher_loop.go b/os/gfsnotify/gfsnotify_watcher_loop.go index 2618239ce..6eb1e1a7d 100644 --- a/os/gfsnotify/gfsnotify_watcher_loop.go +++ b/os/gfsnotify/gfsnotify_watcher_loop.go @@ -134,7 +134,7 @@ func (w *Watcher) eventLoop() { }() } -// getCallbacks searches and returns all callbacks with given . +// getCallbacks searches and returns all callbacks with given `path`. // It also searches its parents for callbacks if they're recursive. func (w *Watcher) getCallbacks(path string) (callbacks []*Callback) { // Firstly add the callbacks of itself.