mirror of
				https://github.com/duke-git/lancet.git
				synced 2025-10-31 18:52:43 +08:00 
			
		
		
		
	update: add some new feature comments for file and slice
This commit is contained in:
		| @@ -6,7 +6,7 @@ | ||||
| <div align="center" style="text-align: center;"> | ||||
|  | ||||
|  | ||||
| [](https://github.com/duke-git/lancet/releases) | ||||
| [](https://github.com/duke-git/lancet/releases) | ||||
| [](https://pkg.go.dev/github.com/duke-git/lancet) | ||||
| [](https://goreportcard.com/report/github.com/duke-git/lancet) | ||||
| [](https://codecov.io/gh/duke-git/lancet) | ||||
| @@ -215,12 +215,17 @@ func main() { | ||||
| func ClearFile(path string) error //write empty string to path file | ||||
| func CreateFile(path string) bool // create a file in path | ||||
| func CopyFile(srcFilePath string, dstFilePath string) error //copy src file to dst file | ||||
| func FileMode(path string) (fs.FileMode, error) //return file's mode and permission | ||||
| func MiMeType(file interface{}) string //return file mime type, file should be string or *os.File | ||||
| func IsExist(path string) bool  //checks if a file or directory exists | ||||
| func IsLink(path string) bool //checks if a file is symbol link or not | ||||
| func IsDir(path string) bool //checks if the path is directy or not | ||||
| func ListFileNames(path string) ([]string, error) //return all file names in the path | ||||
| func RemoveFile(path string) error //remove the path file | ||||
| func ReadFileToString(path string) (string, error) //return string of file content | ||||
| func ReadFileByLine(path string)([]string, error) //read file content by line | ||||
| func Zip(fpath string, destPath string) error //create zip file, fpath could be a single file or a directory | ||||
| func UnZip(zipFile string, destPath string) error //unzip the file and save it to destPath | ||||
| ``` | ||||
|  | ||||
| #### 5. formatter is for data format | ||||
| @@ -398,6 +403,7 @@ func None(slice, function interface{}) bool // return true if all the values in | ||||
| func Filter(slice, function interface{}) interface{} //filter slice, function signature should be func(index int, value interface{}) bool | ||||
| func Find(slice, function interface{}) (interface{}, bool) //iterates over elements of slice, returning the first one that passes a truth test on function.function signature should be func(index int, value interface{}) bool . | ||||
| func FlattenDeep(slice interface{}) interface{} //flattens slice recursive | ||||
| func ForEach(slice, function interface{}) //iterates over elements of slice and invokes function for each element, function signature should be func(index int, value interface{})  | ||||
| func IntSlice(slice interface{}) ([]int, error) //convert value to int slice | ||||
| func InterfaceSlice(slice interface{}) []interface{} //convert value to interface{} slice | ||||
| func Intersection(slices ...interface{}) interface{} //creates a slice of unique values that included by all slices. | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
| <div align="center" style="text-align: center;"> | ||||
|  | ||||
|  | ||||
| [](https://github.com/duke-git/lancet/releases) | ||||
| [](https://github.com/duke-git/lancet/releases) | ||||
| [](https://pkg.go.dev/github.com/duke-git/lancet) | ||||
| [](https://goreportcard.com/report/github.com/duke-git/lancet) | ||||
| [](https://codecov.io/gh/duke-git/lancet) | ||||
| @@ -214,14 +214,19 @@ func main() { | ||||
|  | ||||
| ```go | ||||
| func ClearFile(path string) error //清空文件内容 | ||||
| func IsExist(path string) bool  //判断文件/目录是否存在 | ||||
| func CreateFile(path string) bool //创建文件 | ||||
| func FileMode(path string) (fs.FileMode, error) //返回文件mode信息 | ||||
| func MiMeType(file interface{}) string //返回文件mime类型 | ||||
| func IsExist(path string) bool  //判断文件/目录是否存在 | ||||
| func IsDir(path string) bool //判断是否为目录 | ||||
| func IsLink(path string) bool //检查文件是否为符号链接文件 | ||||
| func RemoveFile(path string) error //删除文件 | ||||
| func CopyFile(srcFilePath string, dstFilePath string) error //复制文件 | ||||
| func ListFileNames(path string) ([]string, error) //列出目录下所有文件名称 | ||||
| func ReadFileToString(path string) (string, error) //读取文件内容为字符串 | ||||
| func ReadFileByLine(path string)([]string, error) //按行读取文件内容 | ||||
| func Zip(fpath string, destPath string) error //压缩文件fpath参数可以是文件或目录,destPath是压缩后目标文件 | ||||
| func UnZip(zipFile string, destPath string) error //解压文件,并将文件存储在destPath目录中 | ||||
| ``` | ||||
|  | ||||
| #### 5. formatter格式化处理包 | ||||
| @@ -399,6 +404,7 @@ func None(slice, function interface{}) bool //slice中所有元素都不符合 | ||||
| func Find(slice, function interface{}) (interface{}, bool)//查找slice中第一个符合条件的元素,函数签名:func(index int, value interface{}) bool | ||||
| func Filter(slice, function interface{}) interface{} //过滤slice, 函数签名:func(index int, value interface{}) bool | ||||
| func FlattenDeep(slice interface{}) interface{} //将slice递归为一维切片。 | ||||
| func ForEach(slice, function interface{}) //遍历切片,在每个元素上执行函数,函数签名:func(index int, value interface{}) | ||||
| func IntSlice(slice interface{}) ([]int, error) //转成int切片 | ||||
| func InterfaceSlice(slice interface{}) []interface{} //转成interface{}切片 | ||||
| func Intersection(slices ...interface{}) interface{} //slice交集,去重 | ||||
|   | ||||
| @@ -154,8 +154,8 @@ func ListFileNames(path string) ([]string, error) { | ||||
| 	return res, nil | ||||
| } | ||||
|  | ||||
| // Zip create zip file, srcFile could be a single file or a directory | ||||
| func Zip(srcFile string, destPath string) error { | ||||
| // Zip create zip file, fpath could be a single file or a directory | ||||
| func Zip(fpath string, destPath string) error { | ||||
| 	zipFile, err := os.Create(destPath) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| @@ -165,7 +165,7 @@ func Zip(srcFile string, destPath string) error { | ||||
| 	archive := zip.NewWriter(zipFile) | ||||
| 	defer archive.Close() | ||||
|  | ||||
| 	filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error { | ||||
| 	filepath.Walk(fpath, func(path string, info os.FileInfo, err error) error { | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| @@ -175,7 +175,7 @@ func Zip(srcFile string, destPath string) error { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/") | ||||
| 		header.Name = strings.TrimPrefix(path, filepath.Dir(fpath)+"/") | ||||
|  | ||||
| 		if info.IsDir() { | ||||
| 			header.Name += "/" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 dudaodong
					dudaodong