gotool

package module
v0.0.0-...-fa9c3f3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 38 Imported by: 0

README

gotool

常用函数工具扩展集合

go get -u github.com/lengnuan-v/gotool 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addslashes

func Addslashes(str string) string

在每个双引号(")前添加反斜杠 str 要转义的字符串

func ArrayChunk

func ArrayChunk(array []interface{}, size int) [][]interface{}

数组分割数组块 array 规定要使用的数组。 size 整数值,规定每个新数组包含多少个元素。

func ArrayColumn

func ArrayColumn(array []interface{}, key string) []interface{}

返回输入数组中某个单一列的值 array 规定要使用的多维数组 key 需要返回值的列 ArrayColumn([][]interface{}{{"id":"a", "name":"b"}, {"id":"c", "name":"d"}}, "id")

func ArrayCombine

func ArrayCombine(s1, s2 []interface{}) map[interface{}]interface{}

合并两个数组来创建一个新数组,其中的一个数组元素为键名,另一个数组的元素为键值

func ArrayKeyExists

func ArrayKeyExists(key interface{}, m map[interface{}]interface{}) bool

检查某个数组中是否存在指定的键名 ArrayKeyExists("a", map[interface{}]interface{"a":"a","b":b})

func ArrayKeys

func ArrayKeys(array map[interface{}]interface{}) []interface{}

返回包含数组中所有键名的一个新数组 array 数组

func ArrayMerge

func ArrayMerge(array ...[]interface{}) []interface{}

把多个数组合并为一个数组 array 数组

func ArrayPop

func ArrayPop(array *[]interface{}) interface{}

删除数组中的最后一个元素 array 数组

func ArrayPush

func ArrayPush(array *[]interface{}, elements ...interface{}) int

在数组尾部添加一个或多个元素 array 数组 elements 添加的值 ArrayPush(&s1, "u", "v")

func ArrayRand

func ArrayRand(array []interface{}) []interface{}

返回数组中的随机键名 array 数组

func ArrayReverse

func ArrayReverse(s []interface{}) []interface{}

相反的元素顺序返回数组

func ArrayShift

func ArrayShift(array *[]interface{}) interface{}

删除数组中第一个元素,并返回被删除元素的值 array 数组

func ArraySlice

func ArraySlice(array []interface{}, offset, length uint) []interface{}

在数组中根据条件取出一段值 array 数组 offset 取出元素的开始位置 length 返回数组的长度

func ArrayUnique

func ArrayUnique(array []interface{}) (newArr []interface{})

移除数组中的重复的值,并返回结果数组 array 规定数组。 ArrayUnique([]string("a", "b", "a"))

func ArrayValues

func ArrayValues(array map[interface{}]interface{}) []interface{}

返回一个包含给定数组中所有键值的数组,但不保留键名 elements 数组

func Base64Decode

func Base64Decode(str string) (string, error)

解码base64编码的数据 str 要编码的数据

func Base64Encode

func Base64Encode(str string) string

使用base64对数据进行编码 str 要编码的数据

func Basename

func Basename(path string) string

返回路径中的文件名部分

func Between

func Between(str, starting, ending string) string

获取字符串中2个字符串之间到内容

func Ceil

func Ceil(value float64) float64

向上舍入为最接近的整数

func Chmod

func Chmod(filename string, mode os.FileMode) bool

改变文件模式

func ChunkSplit

func ChunkSplit(body string, chunklen uint, end string) string

把字符串分割后添加指定end body 要分割的字符串 chunklen 数字值,定义字符串块的长度 end 定义在每个字符串块末端放置的内容 ChunkSplit("abc", 1, "e") => aebece

func CookiesString

func CookiesString(cookies []*http.Cookie) []byte

Cookie 解析 字符串

func Copy

func Copy(source, dest string) (bool, error)

拷贝文件 source 要复制的文件 dest 复制文件的目的地

func Critical

func Critical(args ...interface{})

func Date

func Date(format string) string

获取当前日期时间 format 格式 2006-01-02 15:04:05 必须是这个时间点, 据说是go诞生之日(返回的格式)

func DateTime

func DateTime(format string, timestamp int64) string

时间戳转日期时间 format 格式 2006-01-02 15:04:05 必须是这个时间点, 据说是go诞生之日(返回的格式) timestamp 需要转化的时间戳

func Debug

func Debug(args ...interface{})

func DeletePunctuation

func DeletePunctuation(str string) string

删除标点符号

func Error

func Error(args ...interface{})

func ExecCommand

func ExecCommand(c string) (string, error)

执行本地命令行 cmd 执行的命令行

func Explode

func Explode(separator, str string) []string

字符串转数组 separator 规定在哪里分割字符串。 string 要分割的字符串。 Explode(",", "a,b,c")

func FileExists

func FileExists(filename string) bool

检查文件或目录是否存在 filename 指定的文件或目录

func FileSize

func FileSize(filename string) (int64, error)

返回指定文件的大小

func FloatToString

func FloatToString(f float64, size int) string

float转string size 32 -> float32 64 -> float64

func Floor

func Floor(value float64) float64

向下舍入为最接近的整数

func GetUserHome

func GetUserHome() string

获取当前系统HOME

func Getcwd

func Getcwd() (string, error)

获取当前工作目录

func Gethostname

func Gethostname() (string, error)

获取主机名

func Glob

func Glob(pattern string) ([]string, error)

返回匹配指定模式的文件名或目录

func Goos

func Goos() string

获取当前操作系统

func HTMLEntityDecode

func HTMLEntityDecode(str string) string

把 HTML 实体转换为字符 str 要转换的字符串

func Handler

func Handler(f interface{}, params ...interface{}) []reflect.Value

func Htmlentities

func Htmlentities(str string) string

字符转换为 HTML 实体 str 要转换的字符串

func IP2long

func IP2long(ipAddress string) uint32

将长整数地址转换为(IPv4)Internet标准点分格式的字符串 IP2long("8.8.8.8")

func If

func If(cond bool, a, b interface{}) interface{}

三元表达式

func Implode

func Implode(separator string, array []string) string

数组转字符串 separator 规定数组元素之间放置的内容 array 要组合为字符串的数组。 Implode(",", []string{"a", "b", "c"})

func InArray

func InArray(search interface{}, array interface{}) (exists bool, index int)

搜索数组中是否存在指定的值 search 规定要在数组搜索的值。 array 规定要搜索的数组。 InArray(1, [2]interface{}{"a", 1})

func Info

func Info(args ...interface{})

func Int64ToString

func Int64ToString(i int64) string

int64转成string

func IntToString

func IntToString(i int) string

int转成string:

func IsDir

func IsDir(filename string) (bool, error)

判断给定文件名是否是一个目录 filename 指定的文件或目录

func IsDirCreate

func IsDirCreate(path string)

检测目录是否存在,不存在就创建 path 指定的目录

func IsEmpty

func IsEmpty(val interface{}) bool

检查一个变量是否为空

func IsFile

func IsFile(filename string) bool

检查指定的文件是否是常规的文件

func IsNumeric

func IsNumeric(val interface{}) bool

检测变量是否为数字或数字字符串

func IsReadable

func IsReadable(filename string) bool

判断指定文件名是否可读

func IsWriteable

func IsWriteable(filename string) bool

判断指定的文件是否可写

func JSONDecode

func JSONDecode(data []byte, val interface{}) error

解码JSON字符串

func JSONEncode

func JSONEncode(val interface{}) ([]byte, error)

对变量进行 JSON 编码

func Lcfirst

func Lcfirst(str string) string

首字符转换为小写 str 要转换的字符串

func Log

func Log(dirname ...string) *logging.Logger

func Long2ip

func Long2ip(properAddress uint32) string

将长整数地址转换为(IPv4)Internet标准点分格式的字符串 Long2ip(134744072)

func Ltrim

func Ltrim(str string, charlist ...string) string

移除字符串左侧的空白字符或其他预定义字符 str 要检查的字符串 charlist 从字符串中删除哪些字符

func Max

func Max(nums ...float64) float64

查找最大值

func MbStrlen

func MbStrlen(str string) int

获取字符串的长度 (单个汉字 = 1) str 需要计算长度的字符串

func Md5

func Md5(str string) string

MD5加密 str 要加密的字符串

func Min

func Min(nums ...float64) float64

查找最小值

func Notice

func Notice(args ...interface{})

func Paging

func Paging(total, limit float64) float64

计算分页数

func ParseStr

func ParseStr(encodedString string, result map[string]interface{}) error

把查询字符串解析到变量中 encodedString 要解析的字符串 result 存储变量的数组的名称。该参数指示变量将被存储到数组中 result := make(map[string]interface{}) _ = ParseStr("f1=m&f2=n", result) result => map[f1:m f2:n]

func Pathinfo

func Pathinfo(path string, options int) map[string]string

以数组的形式返回文件路径的信息 path 文件路径 options -1: all; 1: dirname; 2: basename; 4: extension; 8: filename Pathinfo("/home/go/php2go.go.go", -1)

func Quotemeta

func Quotemeta(str string) string

在预定义字符前添加反斜杠 str 要检查的字符串

func Rand

func Rand(min, max int) int

生成随机整数

func ReadFile

func ReadFile(filename string) ([]byte, error)

读取一个文件 filename 规定要读取的文件。

func Realpath

func Realpath(path string) (string, error)

返回绝对路径

func RecursiveListPath

func RecursiveListPath(path string, slice *[]string)

递归路径

func Rename

func Rename(oldname, newname string) error

重命名文件或目录 oldname 要重命名的文件或目录 newname 文件或目录的新名称

func Round

func Round(value float64) float64

浮点数进行四舍五入

func Rtrim

func Rtrim(str string, charlist ...string) string

移除字符串右侧的空白字符或其他预定义字符 str 要检查的字符串 charlist 从字符串中删除哪些字符

func SimilarText

func SimilarText(first, second string, percent *float64) int

计算两个字符串的相似度,并返回匹配字符的数目 first 比较的第一个字符串 second 比较的第二个字符串 percent 百分比相似度的变量名 SimilarText("golang", "google", &percent)

func Sleep

func Sleep(t int64)

停顿、暂停 t 秒数

func StrReplace

func StrReplace(search, replace, str string, count int) string

以其他字符替换字符串中的一些字符(区分大小写) search 要查找的值 replace 替换 search 中的值 str 被搜索的字符串 count 对替换数进行计数的变量, 替换的数量没有限制使用 -1 StrReplace("a","b","abcd", -1)

func StringToFloat

func StringToFloat(str string, size int) (float64, error)

string转float size 32 -> float32 64 -> float64

func StringToInt

func StringToInt(str string) (int, error)

string转成int

func StringToInt64

func StringToInt64(str string) (int64, error)

string转成int64

func Stripos

func Stripos(str, needle string, offset int) int

查找字符串在另一字符串中第一次出现的位置(不区分大小写) str 被搜索的字符串 needle 要查找的字符 offset 在何处开始搜索 1 Stripos("hello word", "w", 1)

func Stripslashes

func Stripslashes(str string) string

删除反斜杠 str 要检查的字符串

func Strlen

func Strlen(str string) int

获取字符串长度 (单个汉字 = 3) str 需要计算长度的字符串

func Strpos

func Strpos(str, needle string, offset int) int

查找字符串在另一字符串中第一次出现的位置(区分大小写) str 被搜索的字符串 needle 要查找的字符 offset 在何处开始搜索 1 Strpos("hello word", "w", 1)

func Strrev

func Strrev(str string) string

反转字符串 str 要反转的字符串

func Strripos

func Strripos(str, needle string, offset int) int

查找字符串在另一字符串中最后一次出现的位置(不区分大小写) str 被搜索的字符串 needle 要查找的字符 offset 在何处开始搜索, 没有限制使用 1 Strripos("hello word", "w", 1)

func Strrpos

func Strrpos(str, needle string, offset int) int

查找字符串在另一字符串中最后一次出现的位置(区分大小写) str 被搜索的字符串 needle 要查找的字符 offset 在何处开始搜索 1 Strrpos("hello word", "w", 1)

func Strstr

func Strstr(str string, search string) string

搜索字符串在另一字符串中的第一次出现 str 被搜索的字符串 search 所搜索的字符串 Strstr("xxx@gmail.com", "@")

func StrtoTime

func StrtoTime(format, strtime string) (int64, error)

日期时间转换时间戳 format 格式 2006-01-02 15:04:05 必须是这个时间点, 据说是go诞生之日 strtime 需要转化时间戳的日期时间

func Strtolower

func Strtolower(str string) string

字符转换为小写 str 要转换的字符串

func Strtoupper

func Strtoupper(str string) string

字符转换为大写 str 要转换的字符串

func Strtr

func Strtr(haystack string, params ...interface{}) string

转换字符串中特定的字符 haystack 要转换的字符串 params 要改变的字符, 要改变为的字符 Strtr("baab", "ab", "01")

func Substr

func Substr(str string, start int, length int) string

返回字符串的一部分 str 要检查的字符串 start 字符串的何处开始 length 要返回的字符串长度 Substr("abc", 0, 2)

func Time

func Time() int64

获取当前时间戳

func Tracefile

func Tracefile(content []byte, filename string, keep bool) (int, error)

创建并写入文件 content 写入的内容 filename 规定要写入的文件。 keep true 已有的数据会被保留 false 已有的数据会被清除

func Trim

func Trim(str string, charlist ...string) string

移除字符串两侧的空白字符或其他预定义字符 str 要检查的字符串 charlist 从字符串中删除哪些字符

func UA

func UA(source ...string) string

随机UA (选择不同的浏览器 UA)

func URLDecode

func URLDecode(str string) (string, error)

解码URL编码的字符串 str 要解码的字符串

func URLEncode

func URLEncode(str string) string

编码 URL 字符串 str 要编码的字符串

func Ucfirst

func Ucfirst(str string) string

首字符转换为大写 str 要转换的字符串

func Ucwords

func Ucwords(str string) string

把字符串中每个单词的首字符转换为大写 str 要转换的字符串

func UnescapeUnicode

func UnescapeUnicode(raw string) (string, error)

Unicode 转中文

func Unlink(filename string) error

删除文件

func Warning

func Warning(args ...interface{})

Types

type ClientOptions

type ClientOptions struct {
	Url     string
	Method  string
	Body    io.Reader
	Header  map[string]string
	Proxy   []byte
	Timeout int64
}

Method GET POST Body bytes.NewReader() Proxy http://IP:Proxy or socks5://Username:Password@IP:Proxy

func (*ClientOptions) HttpRequest

func (c *ClientOptions) HttpRequest() ([]byte, []byte, error)

type DB

type DB struct {
	Dsn    string // dsn
	Driver string
	Prefix string // 前缀
}

Dsn "账号:密码@tcp(IP:端口)/数据库?charset=utf8" Driver mysql/sqlite/oracle/mssql/postgres Prefix 前缀

func (*DB) Count

func (d *DB) Count(tanleName string, cond interface{}) (int64, error)

获取条数

func (*DB) Delete

func (d *DB) Delete(tanleName string, cond interface{}) (int64, error)

删除数据

func (*DB) GetDb

func (d *DB) GetDb() (*gorose.Connection, error)

func (*DB) Insert

func (d *DB) Insert(tanleName string, data interface{}) (int64, error)

新增数据

func (*DB) SelectAll

func (d *DB) SelectAll(tanleName string, fields []string, cond interface{}, order string, limit, offset int) ([]map[string]interface{}, error)

分页查询数据

func (*DB) SelectRow

func (d *DB) SelectRow(tanleName string, fields []string, cond interface{}, order string) (map[string]interface{}, error)

查询一条数据

func (*DB) SelectRows

func (d *DB) SelectRows(tanleName string, fields []string, cond interface{}, order string) ([]map[string]interface{}, error)

查询多条数据

func (*DB) Update

func (d *DB) Update(tanleName string, set map[string]interface{}, cond interface{}) (int64, error)

更新数据

type FTP

type FTP struct {
	Host     string // 地址
	Username string // 用户名
	Password string // 密码
	Port     int    // 端口号
}

func (*FTP) FileDelete

func (f *FTP) FileDelete(filePathName string) error

FTP 删除文件 filePathName 删除文件

func (*FTP) FileDownload

func (f *FTP) FileDownload(filePath, remotePathName string) error

FTP 下载文件 filePath 本地目录 remotePath 远程文件路径名

func (*FTP) FileUpload

func (f *FTP) FileUpload(filePathName string, content []byte) error

FTP 上传文件 filePathName 文件路径名 content 文件内容

func (*FTP) FtpClient

func (f *FTP) FtpClient() (*ftp.ServerConn, error)

type RedisClient

type RedisClient struct {
	Addr     string
	Password string
	DB       int
}

Addr "localhost:6379", Password no password set DB use default DB

func (*RedisClient) DeleteKey

func (r *RedisClient) DeleteKey(key string) int64

删除key

func (*RedisClient) GetKeysCount

func (r *RedisClient) GetKeysCount(pattern string) int

func (*RedisClient) MExpire

func (r *RedisClient) MExpire(duration int64, keys ...string)

func (*RedisClient) SetAdd

func (r *RedisClient) SetAdd(key string, value []string) int64

set 下的增加数据

func (*RedisClient) SetMembersReturnVal

func (r *RedisClient) SetMembersReturnVal(key string) []string

获取set下的 value,返回数组

func (*RedisClient) SortedSetAdd

func (r *RedisClient) SortedSetAdd(key string, values ...redis.Z) int64

func (*RedisClient) SortedZrangeWithScores

func (r *RedisClient) SortedZrangeWithScores(key string) []redis.Z

func (*RedisClient) StrGet

func (r *RedisClient) StrGet(key string) string

func (*RedisClient) StrMGet

func (r *RedisClient) StrMGet(keys ...string) []interface{}

func (*RedisClient) StrMSet

func (r *RedisClient) StrMSet(pairs ...interface{}) string

mset 批量写入

func (*RedisClient) StrSet

func (r *RedisClient) StrSet(key, value string) string

type SFTP

type SFTP struct {
	Host     string // 地址
	Username string // 用户名
	Password string // 密码
	Port     int    // 端口号
}

func (*SFTP) FileDelete

func (s *SFTP) FileDelete(filePathName string) error

FTP 删除文件 filePathName 删除文件

func (*SFTP) FileDownload

func (s *SFTP) FileDownload(filePath, remotePathName string) error

SFTP 下载文件 filePath 本地目录 remotePath 远程文件路径名

func (*SFTP) FileUpload

func (s *SFTP) FileUpload(filePathName string, content []byte) error

SFTP 上传文件 filePathName 文件路径名 content 文件内容

func (*SFTP) SftpClient

func (s *SFTP) SftpClient() (*sftp.Client, error)

type SSH

type SSH struct {
	Host     string // 地址
	Username string // 用户名
	Password string // 密码
	Port     int    // 端口号
}

func (*SSH) ExecSSH

func (s *SSH) ExecSSH(c string) ([]byte, error)

执行远程SSH命令行 cmd 执行的命令行

func (*SSH) SSHClient

func (s *SSH) SSHClient() (*ssh.Session, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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