gutils

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 32 Imported by: 1

Documentation

Overview

file 文件相关的一些辅助函数

str_convert 字符串,数字相互转换的一些辅助函数

Package of gutils common function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(in, key, iv []byte) ([]byte, error)

AESDecrypt aes decrypt []byte

func AESEncrypt

func AESEncrypt(in, key, iv []byte) ([]byte, error)

AESEncrypt aes encrypt []byte. key = "abcdefghijklmnopqrstuvwxyz123456" iv = "0123456789ABCDEF"

func Abs

func Abs(number float64) float64

Abs abs(num)返回绝对值,返回结果是float64

func Addslashes

func Addslashes(str string) string

Addslashes addslashes()

func Base64Decode

func Base64Decode(str string) (string, error)

Base64Decode base64_decode(str)

func Base64Encode

func Base64Encode(str string) string

Base64Encode base64_encode(str)

func Basename

func Basename(path string) string

Basename basename()

func Bin2hex

func Bin2hex(src []byte) string

Bin2hex converts binary data into hexadecimal representation

func Bindec

func Bindec(str string) (string, error)

Bindec bindec()

func Ceil

func Ceil(value float64) float64

Ceil 产生一个向上取整的数字,php ceil(num)

func CheckPathExist

func CheckPathExist(path string) bool

CheckPathExist check file or path exist

func Chmod

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

Chmod chmod()

func Chown

func Chown(name string, info os.FileInfo) error

Chown 清空文件并保持文件权限不变,并非linux chown操作 Empty the file and keep the file permissions unchanged not the linux chown operation

func Chr

func Chr(ascii int) string

================str chr,ord func====================== Chr returns a one-character string containing the character specified by ascii go1.15 return string(rune(ascii))

func CopyFile

func CopyFile(distName, srcName string) (w int64, err error)

CopyFile 复制文件到另一个文件

func Crc32

func Crc32(str string) uint32

Crc32 calculates the crc32 polynomial of a string

func Decbin

func Decbin(number int64) string

Decbin decbin()

func Empty

func Empty(val interface{}) bool

Empty empty()

func Explode

func Explode(delimiter, str string) []string

=================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.

func Fclose

func Fclose(handle *os.File) error

Fclose fclose()

func Fgetcsv

func Fgetcsv(handle *os.File, delimiter rune, size ...int64) ([][]string, error)

Fgetcsv fgetcsv() 默认当文件大小大于10MB逐行读取内容,否则一次性读取内容 第三个参数可以指定逐行读取的最大文件大小,单位字节 1MB = 1 << 20

func FileChown

func FileChown(filename string, uid, gid int) bool

Chown chown()

func FileExists

func FileExists(filename string) bool

FileExists file_exists()

func FileGetContents

func FileGetContents(filename string) (string, error)

FileGetContents file_get_contents()

func FilePutContents

func FilePutContents(filename string, data string, mode os.FileMode) error

FilePutContents file_put_contents()

func FileSize

func FileSize(filename string) (int64, error)

FileSize filesize()

func Filebase

func Filebase(file string) string

Filebase 获取文件的名称不带后缀 get the name of the file without a suffix

func Fileline

func Fileline(file string, line int) string

Fileline 获取文件名:行数

func Filemtime

func Filemtime(filename string) (int64, error)

Filemtime filemtime()

func Float64ToStr

func Float64ToStr(f64 float64) string

Float64ToStr float64 to string 'e' (-d.dddde±dd,十进制指数)

func Floor

func Floor(value float64) float64

Floor 产生一个向下取整的数字,对应php floor(num)

func Getcwd

func Getcwd() (string, error)

Getcwd getcwd()

func Glob

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

Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').

Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.

func Gunzip

func Gunzip(in []byte) ([]byte, error)

Gunzip decompress data user gunzip

func Gzip

func Gzip(in []byte) ([]byte, error)

Gzip compress data use gzip

func HTMLEntities

func HTMLEntities(str string) string

HTMLEntities htmlentities()

func HTMLEntityDecode

func HTMLEntityDecode(str string) string

HTMLEntityDecode html_entity_decode()

func HTMLSpecialchars

func HTMLSpecialchars(str string) string

=====================html special characters================ HTMLSpecialchars converts special characters to HTML entities

func HTMLSpecialcharsDecode

func HTMLSpecialcharsDecode(str string) string

HTMLSpecialcharsDecode converts special HTML entities back to characters

func HTTPBuildQuery

func HTTPBuildQuery(queryData url.Values) string

HTTPBuildQuery http_build_query() url a=1&b=2

func Hash

func Hash(mem []byte) uint64

Hash : []byte to uint64

func Hex2bin

func Hex2bin(str string) []byte

Hex2bin decodes a hexadecimally encoded binary string

func IP2long

func IP2long(ipAddress string) uint32

========================ip convert=========== IP2long ip2long()

func Implode

func Implode(glue string, pieces []string) string

Implode returns a string containing a string representation of all the slice elements in the same order, with the glue string between each element.

func Int64ToStr

func Int64ToStr(i64 int64) string

Int64ToStr int64-->string

func IntToStr

func IntToStr(n int) string

================str,int,int64,float64 conv func======================= IntToStr int-->string

func IsDir

func IsDir(filename string) (bool, error)

IsDir is_dir()

func IsFile

func IsFile(filename string) bool

IsFile is_file()

func IsNumeric

func IsNumeric(v interface{}) bool

IsNumeric 判断v是否是一个数字类型,php is_numeric(num) Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. In PHP hexadecimal (e.g. 0xf4c3b00c) is not supported, but IsNumeric is supported.

func IsReadable

func IsReadable(filename string) bool

IsReadable is_readable()

func IsWriteable

func IsWriteable(filename string) bool

IsWriteable is_writeable()

func Krand

func Krand(size int, kind int) string

================str krand func=========== Krand 根据kind生成不同风格的指定区间随机字符串 纯数字kind=0,小写字母kind=1 大写字母kind=2,数字+大小写字母kind=3

func LcFirst

func LcFirst(str string) string

LcFirst lcfirst(str) make a string's first character lowercase

func LoadGobData

func LoadGobData(data interface{}, fileName string)

LoadGobData 将gob写入的内容,载入到data中

func Long2ip

func Long2ip(properAddress uint32) string

Long2ip long2ip()

func Ltrim

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

Ltrim ltrim()

func Max

func Max(nums ...float64) float64

Max 获得数字的最大值 max(1,2,3)

func MbStrlen

func MbStrlen(str string) int

MbStrlen mb_strlen()

func Md5

func Md5(str string) string

==============str md5,md5File,sha1,crc32,bin2hex,hex2bin,hash func======= Other advanced functions, please see the tigago/crypto package. md5 func

func Md5File

func Md5File(filename string) (string, error)

Md5File calculates the md5 hash of a given file

func Min

func Min(nums ...float64) float64

Min min(1,2,3)返回最小值

func Mkdir

func Mkdir(filename string, mode os.FileMode) error

Mkdir mkdir()

func NewUUID

func NewUUID() string

=================uuid,rnduuid,uniqid func==================== NewUUID 通过随机数的方式生成uuid 如果rand.Read失败,就按照当前时间戳+随机数进行md5方式生成 该方式生成的uuid有可能存在重复值 返回格式:7999b726-ca3c-42b6-bda2-259f4ac0879a

func Ord

func Ord(character string) rune

Ord return ASCII value of character

func ParseURL

func ParseURL(str string) (*url.URL, error)

ParseURL parses a URL and return its components

func Pathinfo

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

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)

func Rand

func Rand(min, max int) int

Rand 产生[m,n]区间的int随机数 Range: [0, 2147483647]

func RandInt64

func RandInt64(min, max int64) int64

RandInt64 生成m-n之间的随机数

func Rawurldecode

func Rawurldecode(str string) (string, error)

Rawurldecode rawurldecode(str)

func Rawurlencode

func Rawurlencode(str string) string

Rawurlencode rawurlencode(str) Rawurlencode is URL-encode according to RFC 3986. Rawurlencode is identical to URLEncode except that it does not escape space to +.

func Realpath

func Realpath(path string) (string, error)

Realpath realpath()

func Rename

func Rename(oldname, newname string) error

Rename rename()

func RndUuid

func RndUuid() string

RndUuid 基于时间ns和随机数实现唯一的uuid 在单台机器上是不会出现重复的uuid 如果要在分布式的架构上生成不重复的uuid 只需要在rndStr的前面加一些自定义的字符串 返回格式:eba1e8cd-0460-4910-49c6-44bdf3cf024d

func RndUuidMd5

func RndUuidMd5() string

RndUuidMd5 uuid

func Round

func Round(f float64, n int) float64

Round 对浮点数进行四舍五入操作比如 12.125保留2位小数==>12.13

func Rtrim

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

Rtrim rtrim()

func RunShell

func RunShell(exeStr string) (string, error)

RunShell 运行shell脚本

func Sha1

func Sha1(str string) string

sha1 string

func Sha1File

func Sha1File(path string) (string, error)

Sha1File calculates the sha1 hash of a file

func Stat

func Stat(filename string) (os.FileInfo, error)

Stat stat()

func StoreGobData

func StoreGobData(data interface{}, fileName string) error

StoreGobData store gob data

func StrJoin

func StrJoin(sep string, str ...string) string

===================str join func======================== StrJoin 多个字符串按照指定的分隔符进行拼接

func StrJoinByBuf

func StrJoinByBuf(str ...string) string

StrJoinByBuf 通过buf缓冲区的方式连接字符串

func StrRepeat

func StrRepeat(input string, multiplier int) string

StrRepeat str_repeat()

func StrReplace

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

StrReplace str_replace()

func StrShuffle

func StrShuffle(str string) string

StrShuffle str_shuffle(str)

func StrToFloat64

func StrToFloat64(str string) float64

StrToFloat64 string--->float64

func StrToInt

func StrToInt(s string) int

StrToInt string-->int

func StrToInt64

func StrToInt64(s string) int64

StrToInt64 string--> int64

func Stripos

func Stripos(haystack, needle string) int

Stripos find position of the first occurrence of a case-insensitive substring in a string

func Stripslashes

func Stripslashes(str string) string

Stripslashes stripslashes()

func Strlen

func Strlen(str string) int

Strlen get string length A multi-byte character is counted as 1

func Strpos

func Strpos(haystack, needle string) int

=================str strpos,Strrpos,stripos,Strripos func==================== Strpos find position of first occurrence of string in a string It's multi-byte safe. return -1 if can not find the substring

func Strripos

func Strripos(haystack, needle string) int

Strripos find the position of the last occurrence of a case-insensitive substring in a string

func Strrpos

func Strrpos(haystack, needle string) int

Strrpos find the position of the last occurrence of a substring in a string

func Strstr

func Strstr(haystack string, needle string) string

Strstr strstr()

func Strtolower

func Strtolower(str string) string

Strtolower strtolower(str) makes a string lowercase

func Strtoupper

func Strtoupper(str string) string

Strtoupper strtoupper(str) makes a string uppercase

func Substr

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

Substr substr()

func Touch

func Touch(filename string) (bool, error)

Touch touch()

func Trim

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

Trim trim()

func URLDecode

func URLDecode(str string) (string, error)

URLDecode decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character.

func URLEncode

func URLEncode(str string) string

URLEncode returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.

func UcFirst

func UcFirst(str string) string

UcFirst ucfirst(str) make a string's first character uppercase

func Ucwords

func Ucwords(str string) string

Ucwords ucwords(str) uppercases the first character of each word in a string

func Uniqid

func Uniqid(prefix string) string

Uniqid uniqid()

func Unlink(filename string) error

Unlink unlink()

func Uuid

func Uuid() string

Uuid uuid of version4 返回格式:eba1e8cd0460491049c644bdf3cf024d

func Xss

func Xss(str string) string

=====================str xss,XssUnescape func============= Xss 防止xss攻击

func XssUnescape

func XssUnescape(str string) string

XssUnescape 还原xss字符串

Types

This section is empty.

Jump to

Keyboard shortcuts

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