gutils

package
v1.12.22 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 24 Imported by: 5

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 Bin2hex

func Bin2hex(src []byte) string

Bin2hex converts binary data into hexadecimal representation

func Bindec

func Bindec(str string) (string, error)

Bindec bindec()

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 Crc32

func Crc32(str string) uint32

Crc32 calculates the crc32 polynomial of a string

func DeAES

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

DeAES aes decode

func Decbin

func Decbin(number int64) string

Decbin decbin()

func Empty

func Empty(val interface{}) bool

Empty empty()

func EnAES

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

=================str aes/des func========================== key = "abcdefghijklmnopqrstuvwxyz123456" iv = "0123456789ABCDEF"

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 Float64ToStr

func Float64ToStr(f64 float64) string

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

func HTMLEntities added in v1.11.12

func HTMLEntities(str string) string

HTMLEntities htmlentities()

func HTMLEntityDecode added in v1.11.12

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 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 Long2ip

func Long2ip(properAddress uint32) string

Long2ip long2ip()

func Ltrim

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

Ltrim ltrim()

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 thinkgo/crypto package. md5 func

func Md5File

func Md5File(filename string) (string, error)

Md5File calculates the md5 hash of a given file

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 added in v1.11.13

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

ParseURL parses a URL and return its components

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 RndUuid

func RndUuid() string

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

func Rtrim

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

Rtrim rtrim()

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