Documentation ¶
Overview ¶
Package gspath 实现了文件索引和目录搜索功能。
它按照目录添加的顺序,内部高效地进行文件搜索。 注意: 如果启用了缓存功能,在添加或删除文件后,会有一个搜索延迟。
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) Size() int
- func (sp *SPath) X设置值(path string) (realPath string, err error)
- type SPathCacheItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Search ¶
Search 在路径 `root` 下搜索文件 `name`。 参数 `root` 应为一个绝对路径。出于性能考虑,它不会自动将 `root` 转换为绝对路径。 可选参数 `indexFiles` 指定了在结果是目录时要搜索的索引文件列表。 例如,如果结果 `filePath` 是一个目录,并且 `indexFiles` 是 [index.html, main.html],那么它还会在 `filePath` 下搜索 [index.html, main.html]。 如果找到其中任意一个文件,它将返回该文件的绝对路径,否则返回 `filePath`。
func SearchWithCache ¶
SearchWithCache 在启用缓存功能的情况下,搜索路径`root`下的文件`name`。 参数`root`应为绝对路径。出于性能考虑,它不会自动将`root`转换为绝对路径。 可选参数`indexFiles`用于指定当结果是目录时要搜索的索引文件。 例如,如果结果`filePath`是一个目录,并且`indexFiles`为[index.html, main.html],那么它还会在`filePath`下搜索[index.html, main.html]。 如果找到其中任何一个文件,则返回该绝对文件路径,否则返回`filePath`。
Types ¶
type SPath ¶
type SPath struct {
// contains filtered or unexported fields
}
SPath 管理路径搜索功能。
func Get ¶
Get根据给定路径创建并返回一个搜索管理器实例。 参数`cache`用于指定此管理器是否启用缓存功能。 如果启用了缓存功能,它会异步地递归扫描该路径, 并使用gfsnotify包更新所有子文件/文件夹到缓存中。
type SPathCacheItem ¶
type SPathCacheItem struct {
// contains filtered or unexported fields
}
SPathCacheItem 是一个用于搜索的缓存项。