文件搜索类

package
v0.0.0-...-2910145 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package gspath 实现了文件索引和目录搜索功能。

它按照目录添加的顺序,内部高效地进行文件搜索。 注意: 如果启用了缓存功能,在添加或删除文件后,会有一个搜索延迟。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Search(root string, name string, indexFiles ...string) (filePath string, isDir bool)

Search 在路径 `root` 下搜索文件 `name`。 参数 `root` 应为一个绝对路径。出于性能考虑,它不会自动将 `root` 转换为绝对路径。 可选参数 `indexFiles` 指定了在结果是目录时要搜索的索引文件列表。 例如,如果结果 `filePath` 是一个目录,并且 `indexFiles` 是 [index.html, main.html],那么它还会在 `filePath` 下搜索 [index.html, main.html]。 如果找到其中任意一个文件,它将返回该文件的绝对路径,否则返回 `filePath`。

func SearchWithCache

func SearchWithCache(root string, name string, indexFiles ...string) (filePath string, isDir bool)

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

func Get(root string, cache bool) *SPath

Get根据给定路径创建并返回一个搜索管理器实例。 参数`cache`用于指定此管理器是否启用缓存功能。 如果启用了缓存功能,它会异步地递归扫描该路径, 并使用gfsnotify包更新所有子文件/文件夹到缓存中。

func New

func New(path string, cache bool) *SPath

New 创建并返回一个新的路径搜索管理器。

func (*SPath) Add

func (sp *SPath) Add(path string) (realPath string, err error)

Add 向管理器添加更多搜索目录。 管理器将按照添加顺序搜索文件。

func (*SPath) AllPaths

func (sp *SPath) AllPaths() []string

AllPaths 返回缓存在manager中的所有路径。

func (*SPath) Paths

func (sp *SPath) Paths() []string

Paths 返回所有搜索目录。

func (*SPath) Remove

func (sp *SPath) Remove(path string)

Remove 从管理器的缓存文件中删除指定`path`。 参数`path`可以是绝对路径,也可以只是一个相对文件名。

func (*SPath) Search

func (sp *SPath) Search(name string, indexFiles ...string) (filePath string, isDir bool)

Search 在manager中搜索文件`name`。 可选参数`indexFiles`指定了当结果为目录时需要搜索的索引文件。 例如,如果结果`filePath`是一个目录,并且`indexFiles`是[index.html, main.html], 它还会在`filePath`下搜索[index.html, main.html]。如果有任何一项被找到,它将返回该绝对文件路径, 否则返回`filePath`。

func (*SPath) Size

func (sp *SPath) Size() int

Size 返回搜索目录的数量。

func (*SPath) X设置值

func (sp *SPath) X设置值(path string) (realPath string, err error)

Set 删除所有其他搜索目录,并为此管理器设置搜索目录。

type SPathCacheItem

type SPathCacheItem struct {
	// contains filtered or unexported fields
}

SPathCacheItem 是一个用于搜索的缓存项。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL