common

package module
v0.0.0-...-201b726 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 15 Imported by: 2

Documentation

Overview

https://www.jianshu.com/p/38f5213b8510

Index

Constants

View Source
const DATE_TIME_FOMART string = "2006-01-02 15:04:05"
View Source
const DATE_TIME_FOMART_SIMPLE string = "20060102150405"
View Source
const DATE_TIME_FOMART_YMD string = "2006/01/02"
View Source
const DATE_TIME_FOMART_YMD_SIMPLE string = "20060102"
View Source
const OS_DARWIN string = `darwin`
View Source
const OS_FREEBSD string = `freebsd`
View Source
const OS_LINUX string = `linux`
View Source
const OS_WINDOWS string = `windows`
View Source
const PATTERN_DEFAULT string = "0"

搜索模式(忽略模式)

0 : 默认
1 : 包含
2 : 相等
3 : 以开头
4 : 以结尾
5 : 正则表达式
View Source
const PATTERN_EQUAL string = "2"
View Source
const PATTERN_INCLUDE string = "1"
View Source
const PATTERN_PREFIX string = "3"
View Source
const PATTERN_REGEXP string = "5"
View Source
const PATTERN_SUFFIX string = "4"
View Source
const S_BACKLASH string = `\`
View Source
const S_BRACE_LEFT string = `{`

大括号

View Source
const S_BRACE_RIGHT string = `}`
View Source
const S_BRACKET_LEFT string = `[`

中括号

View Source
const S_BRACKET_RIGHT string = `]`
View Source
const S_COLON string = ":"
View Source
const S_COMMA string = ","
View Source
const S_DOT string = `.`
View Source
const S_DOUBLE_BACKLASH string = `\\`
View Source
const S_DOUBLE_QOTATION string = `"`
View Source
const S_EMPTY string = ""
View Source
const S_EMPTY_LINE string = `
`
View Source
const S_INDENT string = "  "
View Source
const S_PARENTHESE_LEFT string = `(`

小括号

View Source
const S_PARENTHESE_RIGHT string = `)`
View Source
const S_QOTATION string = "'"
View Source
const S_SEMICOLON string = ";"
View Source
const S_SLASH string = `/`
View Source
const S_SPACE string = " "
View Source
const S_UNDERBAR string = "_"
View Source
const S_ZERO string = "0"

Variables

This section is empty.

Functions

func CamelToSnake

func CamelToSnake(s string) string

驼峰转下划线

含有换行符

func CamelToSnakeLine

func CamelToSnakeLine(s string) string

驼峰转下划线

无换行符

func ContainsAll

func ContainsAll(s string, list []string) (isContains bool)

判断目标字符串部分是否包含数组中所有项目

func Copy

func Copy(list []string, destPath string)

复制多个文件到指定目录

func CopyOne

func CopyOne(src string, dst string) error

单文件复制

func CreateTree

func CreateTree(rootPath string, file []string, isCreateFile bool) error

创建目录树和文件

func CurrentDir

func CurrentDir() string

获取程序运行路径 参考:

https://blog.csdn.net/sufu1065/article/details/80116627

func Duplicate

func Duplicate(slice []string) []string

去除重复

func FileName

func FileName(filePath string, separator string) string

在文件全路径中截取文件名

func FilePath

func FilePath(filePath string, separator string) string

在文件全路径中截取路径

func GetDataMap

func GetDataMap(db *sql.DB, sSql string) ([]map[string]interface{}, error)

SQL查询结果放到Map中 参考(引用):

https://www.cnblogs.com/mafeng/p/6207702.html
https://stackoverflow.com/questions/19991541/dumping-mysql-tables-to-json-with-golang

func HasSuffix

func HasSuffix(s string, f string) (has bool)

判断目标字符串的末尾是否含有指定的字符串,忽略大小写

func HyphenToCamelLine

func HyphenToCamelLine(s string, isUpFirst bool, convOther bool) string

短线连接字符串转驼峰(首字母转大写)

无换行符

例:

test_id  => TestId
test_place_name  => TestPlaceName

isUpFirst : true: 首字母转大写 false:首字母转小写 convOther : true: 非短线连接转换成小写 false: 非短线连接不转换

func InArray

func InArray(s string, list []string) int

目标字符串如果在数组中,返回下标

func IsAllEmpty

func IsAllEmpty(list []string) (isEmpty bool)

判断数组各元素是否是空字符串或空格

func IsExist

func IsExist(path string) bool

引用: https://www.cnblogs.com/wangqishu/p/5147107.html 判断文件或目录是否存在

func IsInArray

func IsInArray(s string, list []string) (isIn bool)

判断目标字符串是否是在数组中

func IsInPrefix

func IsInPrefix(s string, list []string) (isIn bool)

判断目标字符串的开头是否含有数组中指定的字符串

func IsInSuffix

func IsInSuffix(s string, list []string) (isIn bool)

判断目标字符串的末尾是否含有数组中指定的字符串

func IsPartInArray

func IsPartInArray(s string, list []string) (isIn bool)

判断目标字符串部分是否是在数组中

func JsonArrayToMap

func JsonArrayToMap(sJson string) (result []map[string]interface{}, err error)

JSON(数组)字符串转换成Map

func JsonFileToMap

func JsonFileToMap(jsonFile string) (result interface{}, err error)

JSON文件转换成Map

func JsonToMap

func JsonToMap(sJson string) (result map[string]interface{}, err error)

JSON字符串转换成Map

func LowerFirst

func LowerFirst(s string) string

/ 首字母转小写

func Merge

func Merge(srcFile []string, outFileName string)

参考: https://www.golangtc.com/t/53749f5d320b521bba000007 多个文件合并成一个文件

func Now

func Now(format string) string

现在日期(现在时刻)

DATE_TIME_FOMART
DATE_TIME_FOMART_YMD

func OutFile

func OutFile(filename string, obj interface{}) error

输出到文件

func OutTerminal

func OutTerminal(obj interface{})

输出到控制台

func ReadFile

func ReadFile(filename string) (string, error)

/ 读取文件内容 / 本方法适用于小文件

func RemoveEmpty

func RemoveEmpty(slice []string) []string

删除字符串切片中的空字符串 参考:

https://blog.csdn.net/fwhezfwhez/article/details/79931415

func SearchByNamePartType

func SearchByNamePartType(path []string, fileNamePart []string, fileType []string, ignorePath []string) []string

快捷搜索 以目标文件名关键字搜索多个目录下的指定文件类型, 返回文件全路径切片

path : 搜索目录 fileNamePart : 目标文件名关键字 fileType : 搜索文件类型 ignorePath : 忽略目录(设置此项有助于提高查找效率),例:[]string{".git", ".svn"}

func SearchByType

func SearchByType(path []string, fileType []string, ignorePath []string) []string

快捷搜索 搜索多个目录下的指定文件类型, 返回文件全路径切片

path : 搜索目录 fileType : 搜索文件类型 ignorePath : 忽略目录(设置此项有助于提高查找效率),例:[]string{".git", ".svn"}

func SearchFile

func SearchFile(option SearchOption) []string

搜索多个目录下的文件,返回文件全路径切片 添加参数判断

目标文件类型已指定, 忽略文件类型无须指定。后续处理中忽略文件类型作为空处理

result : 文件全路径切片 option : 搜索选项

func SearchXlsx

func SearchXlsx(path []string, ignorePath []string) []string

快捷搜索XLSX(XLSM)文件

path : 搜索目录 ignorePath : 忽略目录(设置此项有助于提高查找效率),例:[]string{".git", ".svn"}

func SnakeToCamel

func SnakeToCamel(s string, isUpFirst bool, convOther bool) string

下划线连接字符串转驼峰

含有换行符

isUpFirst : true: 首字母转大写 false:首字母转小写 convOther : true: 非下划线连接转换成小写 false: 非下划线连接不转换

func SnakeToCamelLine

func SnakeToCamelLine(s string, isUpFirst bool, convOther bool) string

下划线连接字符串转驼峰(首字母转大写)

无换行符

例:

test_id  => TestId
test_place_name  => TestPlaceName

isUpFirst : true: 首字母转大写 false:首字母转小写 convOther : true: 非下划线连接转换成小写 false: 非下划线连接不转换

func StringArrayToByte

func StringArrayToByte(sa []string) []byte

字符串数组转换拼接成一个字符数组

各字符串间添加换行符

func ToDecimal

func ToDecimal(value float64, c int) float64

func UperFirst

func UperFirst(s string) string

/ 首字母转大写

func WriteFile

func WriteFile(filename string, strarr []string) error

将字符串数组写入指定文件

各字符串间添加换行符

Types

type ExplorerOption

type ExplorerOption struct {
	RootPath      []string `yaml:"rootPath"`      // 目标根目录
	SearchSubPath bool     `yaml:"searchSubPath"` // 搜索子目录
	IgnorePath    []string `yaml:"ignorePath"`    // 忽略目录
	IgnoreFile    []string `yaml:"ignoreFile"`    // 忽略文件
}

遍历选项

type FileInfo

type FileInfo struct {
	File     string      `json:"file"`     // 文件全路径
	FileName string      `json:"fileName"` // 文件名
	FileType string      `json:"fileType"` // 文件类型
	Size     int64       `json:"size"`     // 文件大小
	Mode     os.FileMode `json:"mode"`     // 文件模式
	ModTime  string      `json:"modTime"`  // 最终修改时间

}

文件信息(自定义FileInfo, 区别于os.FileInfo)

type SearchOption

type SearchOption struct {
	RootPath           []string `yaml:"rootPath"`           // 目标根目录
	SearchSubPath      bool     `yaml:"searchSubPath"`      // 搜索子目录
	MatchCase          bool     `yaml:"matchCase"`          // 区分大小写
	FileNamePart       []string `yaml:"fileNamePart"`       // 目标文件名关键字
	FileType           []string `yaml:"fileType"`           // 目标文件类型
	Pattern            string   `yaml:"pattern"`            // 搜索模式
	IgnorePath         []string `yaml:"ignorePath"`         // 忽略目录(目录名完全相同,设置此项有助于提高搜索效率,常用忽略目录: .git, .svn)
	IgnoreFileNamePart []string `yaml:"ignoreFileNamePart"` // 忽略文件名关键字
	IgnoreType         []string `yaml:"ignoreType"`         // 忽略文件类型
	IgnorePattern      string   `yaml:"ignorePattern"`      // 忽略模式
	ShowDetail         bool     `yaml:"showDetail"`         // 是否显示文件详细信息标志
}

搜索选项

type SearchResult

type SearchResult struct {
	File     []string   `json:"file"`     // 文件全路径
	FileInfo []FileInfo `json:"fileInfo"` // 文件信息
	Count    int        `json:"count"`    // 文件总数
	ErrInfo  []string   `json:"errInfo"`  // 错误信息
	ExInfo   []string   `json:"exInfo"`   // 其它信息
}

搜索结果

func Search(option SearchOption) (result SearchResult)

搜索多个目录下的文件 添加参数判断

目标文件类型已指定, 忽略文件类型无须指定。后续处理中忽略文件类型作为空处理

result : 搜索结果 option : 搜索选项

type Stack

type Stack []interface{}

func (Stack) Cap

func (stack Stack) Cap() int

func (Stack) IsEmpty

func (stack Stack) IsEmpty() bool

func (Stack) Len

func (stack Stack) Len() int

func (*Stack) Pop

func (stack *Stack) Pop() (interface{}, error)

func (*Stack) Push

func (stack *Stack) Push(value interface{})

func (Stack) Top

func (stack Stack) Top() (interface{}, error)

type TreeNode

type TreeNode struct {
	Key      string      `json:"key"`
	Label    string      `json:"label"`
	Path     string      `json:"path"`
	Children []*TreeNode `json:"children"`
	IsLeaf   bool        `json:"isLeaf"`
}

树节点

func Explorer

func Explorer(option ExplorerOption) (tree TreeNode)

遍历多个目录下的文件 option : 遍历选项 tree : 遍历结果

Jump to

Keyboard shortcuts

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