gspath

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gspath implements file index and search for folders.

搜索目录管理, 可以添加搜索目录,按照添加的优先级进行文件检索,并在内部进行高效缓存处理(可选)。 注意:当开启缓存功能后,在新增/删除文件时,会存在检索延迟。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

检索root目录(必须为绝对路径)下面的name文件的绝对路径,indexFiles用于指定当检索到的结果为目录时,同时检索是否存在这些indexFiles文件

func SearchWithCache

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

检索root目录(必须为绝对路径)下面的name文件的绝对路径,indexFiles用于指定当检索到的结果为目录时,同时检索是否存在这些indexFiles文件

Types

type SPath

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

文件目录搜索管理对象

func Get

func Get(root string, cache bool) *SPath

创建/获取一个单例的搜索对象, root必须为目录的绝对路径

func New

func New(path string, cache bool) *SPath

创建一个搜索对象

func (*SPath) Add

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

添加搜索路径

func (*SPath) AllPaths

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

返回当前对象缓存的所有路径列表

func (*SPath) Paths

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

返回当前对象搜索目录路径列表

func (*SPath) Remove

func (sp *SPath) Remove(path string)

从搜索路径中移除指定的文件,这样该文件无法给搜索。 path可以是绝对路径,也可以相对路径。

func (*SPath) Search

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

给定的name只是相对文件路径,找不到该文件时,返回空字符串; 当给定indexFiles时,如果name是一个目录,那么会进一步检索其下对应的indexFiles文件是否存在,存在则返回indexFile绝对路径; 否则返回name目录绝对路径。

func (*SPath) Set

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

设置搜索路径,只保留当前设置项,其他搜索路径被清空

func (*SPath) Size

func (sp *SPath) Size() int

当前的搜索路径数量

type SPathCacheItem

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

文件搜索缓存项

Jump to

Keyboard shortcuts

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