package
1.3.48
Repository: https://github.com/sandwich-go/boost.git
Documentation: pkg.go.dev

# README

xos

系统跨平台辅助函数

  • 支持文件、目录拷贝
  • 支持目录创建删除遍历等操作
  • 支持判断目录、文件是否存在
  • 支持文件内容获取、写入
  • 支持文件隐藏、取消隐藏

例子

var file, dir = "a.go", "b"
fmt.Printf("file: %s, exists? %v\n", file, ExistsFile(file))
fmt.Printf("dir: %s, exists? %v\n", dir, ExistsDir(dir))

Output:

file: a.go, exists? false
dir: b, exists? false

# Functions

Copy copies src to dest, doesn't matter if src is a directory or a file.
go:generate optiongen --option_return_previous=false --option_prefix=WithCopy.
CreateDirAll is similar to TouchDirAll but returns error if the deepest directory was not empty.
EnvGet 获取环境变量值,如果未找到,则返回 def 值.
Exists 指定的文件或者目录是否存在 如果发生了非 os.ErrNotExist 错误,则认为存在.
ExistsDir 给定的 filePath 是否存在且是一个目录,如果 filePath 存在但是是一个文件也会返回错误 如果发生了非 os.ErrNotExist 错误,则认为存在.
ExistsFile 给定的 fileName 是否存在且是一个文件,如果 fileName 存在但是是一个目录也会返回 false 如果发生了非 os.ErrNotExist 错误,则认为存在.
Ext 返回后缀,例如 'xxx.go' => '.go'.
FileCopyToDir the src file to dst.
FileGetContents 获取文件内容.
FilePathWalkFollowLink 遍历目录.
FilePutContents 写入文件.
FileWalkFunc 只有指定的ext为合法文件.
FileWalkFuncWithExcludeFilter filepath.WalkFunc 通过excluded过滤不合法文件,如指定了ext则只有ext扩展类型的文件合法.
FileWalkFuncWithIncludeFilter filepath.WalkFunc 通过include过滤合法的文件,如指定了ext则只有ext扩展类型的文件合法.
ForceHide 强制隐藏指定文件,返回被隐藏文件的名称,若已存在相同名称的隐藏文件,则会被覆盖.
ForceUnHide 强制取消隐藏指定文件,返回被取消隐藏文件的名称,若已存在相同名称的取消隐藏文件,则会被覆盖.
FuncBaseNameUsingReflect 使用反射获取基础函数名.
FuncFullNameUsingReflect 使用反射获取函数名.
GetActuallyDir 获取真实目录,如果root为一个link则寻找link的真实目录.
GetShell returns the shell command depending on current working operation system.
GetShellOption returns the shell option depending on current working operating system.
Hide 隐藏指定文件,返回被隐藏文件的名称.
InstallCopyOptionsWatchDog the installed func will called when NewCopyOptions called.
IsDirWriteable checks if dir is writable by writing and removing a file to dir.
IsEmpty 检测目录是否为空,如目录下存在隐藏文件也会认为是非空目录.
IsGoRun returns true if the binary is run from a go run command.
IsHidden 判断是否为隐藏文件.
IsHiddenOrInHiddenDir 判断指定文件是否为隐藏文件,或者包含在隐藏目录中.
Mkdir 创建目录.
MkdirAll 创建 path 的目录.
MustFilePutContents 写入文件,如果发生错误则panic.
MustGetBinaryFilePath returns binary path if the binary is run from a go run command.
MustGetFileWriter 获取写文件句柄 filePath 指定文件 prepend 是否保留源数据,如果保留,则源数据会被追加到文件尾.
NewCopyOptions new CopyOptions.
ReadDir returns the filenames in the given directory in sorted order.
ReadDirWithExt returns the filenames in the given directory in sorted order.
RemoveDirs 删除指定目录下所有内容.
RemoveEmptyDirs 删除空目录 若目录不为空,则报错.
RemoveFilesUnderDir 删除目录下的文件.
RemoveSubDirsUnderDir 删除指定目录下的子目录.
SearchBinary 查找二进制文件.
SearchBinaryPath searches the binary <file> in PATH environment.
TouchDirAll is similar to os.MkdirAll.
UnHide 取消隐藏指定文件,返回被取消隐藏文件的名称.
WithCopyAddPermission option func for filed AddPermission.
WithCopyOnSymlink option func for filed OnSymlink.
WithCopySkip option func for filed Skip.
WithCopySync option func for filed Sync.

# Constants

Deep creates hard-copy of contents.
No description provided by the author
Shallow creates new symlink to the dest of symlink.
Skip does nothing with symlink.

# Variables

ExistsTreatErrorAsExist Exists函数组获取是否存在时,如果发生了非os.ErrNotExist错误,视作存在或者不存在,减轻逻辑层判断负担.

# Structs

CopyOptions should use NewCopyOptions to initialize it.

# Interfaces

CopyOptionsInterface visitor + ApplyOption interface for CopyOptions.
CopyOptionsVisitor visitor interface for CopyOptions.

# Type aliases

CopyOption option func.
SymlinkAction represents what to do on symlink.