Documentation ¶
Overview ¶
Package gspath implements file index and search for folders.
It searches file internally with high performance in order by the directory adding sequence. Note that: If caching feature enabled, there would be a searching delay after adding/deleting files.
Package gspath implements file index and search for folders.
Index ¶
- func Search(root string, name string, indexFiles ...string) (filePath string, isDir bool)
- func SearchWithCache(root string, name string, indexFiles ...string) (filePath string, isDir bool)
- type SPath
- func (sp *SPath) Add(path string) (realPath string, err error)
- func (sp *SPath) AllPaths() []string
- func (sp *SPath) Paths() []string
- func (sp *SPath) Remove(path string)
- func (sp *SPath) Search(name string, indexFiles ...string) (filePath string, isDir bool)
- func (sp *SPath) Set(path string) (realPath string, err error)
- func (sp *SPath) Size() int
- type SPathCacheItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Search ¶
Search searches file `name` under path `root`. The parameter `root` should be a absolute path. It will not automatically convert `root` to absolute path for performance reason. The optional parameter `indexFiles` specifies the searching index files when the result is a directory. For example, if the result `filePath` is a directory, and `indexFiles` is [index.html, main.html], it will also search [index.html, main.html] under `filePath`. It returns the absolute file path if any of them found, or else it returns `filePath`.
func SearchWithCache ¶
SearchWithCache searches file `name` under path `root` with cache feature enabled. The parameter `root` should be a absolute path. It will not automatically convert `root` to absolute path for performance reason. The optional parameter `indexFiles` specifies the searching index files when the result is a directory. For example, if the result `filePath` is a directory, and `indexFiles` is [index.html, main.html], it will also search [index.html, main.html] under `filePath`. It returns the absolute file path if any of them found, or else it returns `filePath`.
Types ¶
type SPath ¶
type SPath struct {
// contains filtered or unexported fields
}
SPath manages the path searching feature.
func Get ¶
Get creates and returns a instance of searching manager for given path. The parameter `cache` specifies whether using cache feature for this manager. If cache feature is enabled, it asynchronously and recursively scans the path and updates all sub files/folders to the cache using package gfsnotify.
func (*SPath) Add ¶
Add adds more searching directory to the manager. The manager will search file in added order.
func (*SPath) Remove ¶
Remove deletes the `path` from cache files of the manager. The parameter `path` can be either a absolute path or just a relative file name.
func (*SPath) Search ¶
Search searches file `name` in the manager. The optional parameter `indexFiles` specifies the searching index files when the result is a directory. For example, if the result `filePath` is a directory, and `indexFiles` is [index.html, main.html], it will also search [index.html, main.html] under `filePath`. It returns the absolute file path if any of them found, or else it returns `filePath`.
type SPathCacheItem ¶
type SPathCacheItem struct {
// contains filtered or unexported fields
}
SPathCacheItem is a cache item for searching.