Categorygithub.com/go-god/gutils
modulepackage
1.1.0
Repository: https://github.com/go-god/gutils.git
Documentation: pkg.go.dev

# README

gutils

go common func library

# Functions

Abs abs(num)返回绝对值,返回结果是float64.
Addslashes addslashes().
AESDecrypt aes decrypt []byte.
AESEncrypt aes encrypt []byte.
Base64Decode base64_decode(str).
Base64Encode base64_encode(str).
Basename basename().
Bin2hex converts binary data into hexadecimal representation.
Bindec bindec().
Ceil 产生一个向上取整的数字,php ceil(num).
CheckPathExist check file or path exist.
Chmod chmod().
Chown 清空文件并保持文件权限不变,并非linux chown操作 Empty the file and keep the file permissions unchanged not the linux chown operation.
================str chr,ord func====================== Chr returns a one-character string containing the character specified by ascii go1.15 return string(rune(ascii)).
CopyFile 复制文件到另一个文件.
Crc32 calculates the crc32 polynomial of a string.
Decbin decbin().
Empty empty().
=================str explode,implode,strlen================ Explode returns an slice of strings, each of which is a substring of str formed by splitting it on boundaries formed by the string delimiter.
Fclose fclose().
Fgetcsv fgetcsv() 默认当文件大小大于10MB逐行读取内容,否则一次性读取内容 第三个参数可以指定逐行读取的最大文件大小,单位字节 1MB = 1 << 20.
Filebase 获取文件的名称不带后缀 get the name of the file without a suffix.
Chown chown().
FileExists file_exists().
FileGetContents file_get_contents().
Fileline 获取文件名:行数.
Filemtime filemtime().
FilePutContents file_put_contents().
FileSize filesize().
Float64ToStr float64 to string 'e' (-d.dddde±dd,十进制指数).
Floor 产生一个向下取整的数字,对应php floor(num).
Getcwd getcwd().
Glob returns the names of all files matching pattern or nil if there is no matching file.
Gunzip decompress data user gunzip.
Gzip compress data use gzip.
Hash : []byte to uint64.
Hex2bin decodes a hexadecimally encoded binary string.
HTMLEntities htmlentities().
HTMLEntityDecode html_entity_decode().
=====================html special characters================ HTMLSpecialchars converts special characters to HTML entities.
HTMLSpecialcharsDecode converts special HTML entities back to characters.
HTTPBuildQuery http_build_query() url a=1&b=2.
Implode returns a string containing a string representation of all the slice elements in the same order, with the glue string between each element.
Int64ToStr int64-->string.
================str,int,int64,float64 conv func======================= IntToStr int-->string.
========================ip convert=========== IP2long ip2long().
IsDir is_dir().
IsFile is_file().
IsNumeric 判断v是否是一个数字类型,php is_numeric(num) Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part.
IsReadable is_readable().
IsWriteable is_writeable().
================str krand func=========== Krand 根据kind生成不同风格的指定区间随机字符串 纯数字kind=0,小写字母kind=1 大写字母kind=2,数字+大小写字母kind=3.
LcFirst lcfirst(str) make a string's first character lowercase.
LoadGobData 将gob写入的内容,载入到data中.
Long2ip long2ip().
Ltrim ltrim().
Max 获得数字的最大值 max(1,2,3).
MbStrlen mb_strlen().
==============str md5,md5File,sha1,crc32,bin2hex,hex2bin,hash func======= Other advanced functions, please see the go-god/crypto package md5 func.
Md5File calculates the md5 hash of a given file.
Min min(1,2,3)返回最小值.
Mkdir mkdir().
=================uuid,rnduuid,uniqid func==================== NewUUID 通过随机数的方式生成uuid 如果rand.Read失败,就按照当前时间戳+随机数进行md5方式生成 该方式生成的uuid有可能存在重复值 返回格式:7999b726-ca3c-42b6-bda2-259f4ac0879a.
Ord return ASCII value of character.
ParseURL parses a URL and return its components.
Pathinfo pathinfo() -1: all; 1: dirname; 2: basename; 4: extension; 8: filename Usage: Pathinfo("/home/go/path/src/php2go/php2go.go", 1|2|4|8).
Rand 产生[m,n]区间的int随机数 Range: [0, 2147483647].
RandInt64 生成m-n之间的随机数.
Rawurldecode rawurldecode(str).
Rawurlencode rawurlencode(str) Rawurlencode is URL-encode according to RFC 3986.
Realpath realpath().
Rename rename().
RndUuid 基于时间ns和随机数实现唯一的uuid 在单台机器上是不会出现重复的uuid 如果要在分布式的架构上生成不重复的uuid 只需要在rndStr的前面加一些自定义的字符串 返回格式:eba1e8cd-0460-4910-49c6-44bdf3cf024d.
RndUuidMd5 uuid.
Round 对浮点数进行四舍五入操作比如 12.125保留2位小数==>12.13.
Rtrim rtrim().
RunShell 运行shell脚本.
sha1 string.
Sha1File calculates the sha1 hash of a file.
Stat stat().
StoreGobData store gob data.
Stripos find position of the first occurrence of a case-insensitive substring in a string.
Stripslashes stripslashes().
===================str join func======================== StrJoin 多个字符串按照指定的分隔符进行拼接.
StrJoinByBuf 通过buf缓冲区的方式连接字符串.
Strlen get string length A multi-byte character is counted as 1.
=================str strpos,Strrpos,stripos,Strripos func==================== Strpos find position of first occurrence of string in a string It's multi-byte safe.
StrRepeat str_repeat().
StrReplace str_replace().
Strripos find the position of the last occurrence of a case-insensitive substring in a string.
Strrpos find the position of the last occurrence of a substring in a string.
StrShuffle str_shuffle(str).
Strstr strstr().
StrToFloat64 string--->float64.
StrToInt string-->int.
StrToInt64 string--> int64.
Strtolower strtolower(str) makes a string lowercase.
Strtoupper strtoupper(str) makes a string uppercase.
Substr substr().
Touch touch().
Trim trim().
UcFirst ucfirst(str) make a string's first character uppercase.
Ucwords ucwords(str) uppercases the first character of each word in a string.
Uniqid uniqid().
Unlink unlink().
URLDecode decodes any %## encoding in the given string.
URLEncode returns a string in which all non-alphanumeric characters except -_.
Uuid uuid of version4 返回格式:eba1e8cd0460491049c644bdf3cf024d.
=====================str xss,XssUnescape func============= Xss 防止xss攻击.
XssUnescape 还原xss字符串.