gtools

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: GPL-3.0 Imports: 35 Imported by: 0

README

go tools

common tools for golang

Documentation

Index

Constants

View Source
const (
	SecondAHour      int64 = 3600
	MillsSecondAHour       = SecondAHour * 1000
	SecondADay       int64 = 86400
	MillsSecondADay        = SecondADay * 1000
	MillsSecondAYear       = MillsSecondADay * 365
)
View Source
const (
	HttpMethodGet  string = "GET"
	HttpMethodPOST string = "POST"
)

Variables

This section is empty.

Functions

func AbsInt64

func AbsInt64(num int64) int64

func AddSlashes

func AddSlashes(str string) string

func BaiduSignature

func BaiduSignature(params map[string]interface{}, secret string) string

BaiduSignature 空参数值的参数名参与签名,来源:百度开放平台

func Base64Decode

func Base64Decode(data string) ([]byte, error)

base64解码

func Base64Encode

func Base64Encode(data []byte) string

base64编码

func BasicAuth

func BasicAuth(username, password string) string

func BuildEsGeoLocation

func BuildEsGeoLocation(lng, lat string) string

func CalculateAgeByBirthday

func CalculateAgeByBirthday(birthday string) int

func CamelString

func CamelString(s string) string

Camel string, xx_yy to XxYy

func ChangeValueByColName

func ChangeValueByColName(aExt interface{}, colName string, dstValue interface{}) interface{}

ChangeValueByColName 通过反射更改结构体的值

func ClearOnSignal

func ClearOnSignal(handler func())

func ContainNumber

func ContainNumber(str string) (valid bool)

func ConvertTime2Secs

func ConvertTime2Secs(str string) int

*

13:23

func Date2UnixMsec

func Date2UnixMsec(dateStr, layout string) int64

func DecimalMoneyMul100

func DecimalMoneyMul100(moneyStr string) (money int64, err error)

DecimalMoneyMul100 将带小数点的金额转换成数据库中的乘以100后的整数

func DefaultFormReqHeaders

func DefaultFormReqHeaders() map[string]string

func DefaultJsonReqHeaders

func DefaultJsonReqHeaders() map[string]string

func DetectFileByteType

func DetectFileByteType(buf []byte) (extension, mime string, err error)

func DetectFileType

func DetectFileType(filename string) (string, string, error)

func EsGeoLocation2LngLat

func EsGeoLocation2LngLat(location string) (lng, lat string)

func Escape

func Escape(html string) string

func Exists

func Exists(file string) bool

Exists 判断所给路径文件/文件夹是否存在

func ExtractUrls

func ExtractUrls(s string) ([]string, error)

func FieldByName

func FieldByName(rv reflect.Value, colName string) reflect.Value

通过反射取得特定字段

func Float2Str

func Float2Str(f float32) string

func Float642Str

func Float642Str(f float64) string

func FullStack

func FullStack() string

func Gbk2Utf8

func Gbk2Utf8(s []byte) ([]byte, error)

func GenerateMobileCaptcha

func GenerateMobileCaptcha(length int) string

GenerateMobileCaptcha 手机验证在4-8位之间,简单实现

func GenerateRandom

func GenerateRandom(min, max int) int

GenerateRandom 生成一个区间范围的随机数,左闭右开

func GenerateRandom64

func GenerateRandom64(min, max int64) int64

GenerateRandom64 生成一个区间范围的随机数,左闭右开

func GenerateRandomStr

func GenerateRandomStr(length int) string

func GeoDistance

func GeoDistance(lat1, lng1, lat2, lng2 float64) float64

GeoDistance 返回单位为:米

func GetFileExt

func GetFileExt(filename string) (suffix string)

GetFileExt 简易版取文件名后缀,path.Ext()方法会带着个`.`

func GetUnixMillis

func GetUnixMillis() int64

GetUnixMillis Deprecated: Use UnixMillis instead

func Guid

func Guid() string

Guid 方法

func HmacSHA1

func HmacSHA1(key string, data string) string

func HmacSha256

func HmacSha256(date, secret string) string

func Hostname

func Hostname() string

func HumanMoney

func HumanMoney(money int64) string

func HumanUnixMillis

func HumanUnixMillis(t int64) (display string)

func HumanUnixMillisV2

func HumanUnixMillisV2(t int64) (display string)

func IP2Long

func IP2Long(ip string) int64

func Int2Str

func Int2Str(number int) string

func Int642Str

func Int642Str(number int64) string

func IsDir

func IsDir(file string) bool

IsDir 判断所给路径是否为文件夹

func IsFile

func IsFile(file string) bool

IsFile 判断所给路径是否为文件

func IsNumber

func IsNumber(str string) (valid bool)

IsNumber 判断是否都是数字

func JSONMarshal

func JSONMarshal(v interface{}) ([]byte, error)

直接json.Marshal , 会把 < > & 转成 unicode 编码 JSONMarshal 解决直接json.Marshal 后单引号,双引号,< > & 符号的问题

func JsonEncode

func JsonEncode(d interface{}) (jsonStr string, err error)

func Long2IP4

func Long2IP4(ipLong int64) string

func MaxInt64

func MaxInt64(x, y int64) int64

MaxInt64 求最大值.

func Md5

func Md5(s string) string

md5方法

func Md5Bytes

func Md5Bytes(buf []byte) string

func MinInt64

func MinInt64(x, y int64) int64

func MobileMask

func MobileMask(mobile string) string

func MoneyDisplay

func MoneyDisplay(money int64) string

func NaturalDay

func NaturalDay(offset int64) (um int64)

NaturalDay 自然日的0点

func NicknameMask

func NicknameMask(nickname string) string

func NumberFormat

func NumberFormat(number interface{}) string

NumberFormat 输出格式化数字,千分位以逗号分割

func ParseCookie

func ParseCookie(cookie, key string) (value string, err error)

func ParseTableName

func ParseTableName(sql string) (name string, err error)

ParseTableName 从SQL语句中解析主表名

func ParseTargetList

func ParseTargetList(str string) []string

func PasswordEncrypt

func PasswordEncrypt(password string, salt int64) string

func PickRandomEmoji

func PickRandomEmoji() string

func RFC3339TimeTransfer

func RFC3339TimeTransfer(datetime string) int64

func RawUrlEncode

func RawUrlEncode(s string) (r string)

func RealNameMask

func RealNameMask(realName string) (maskStr string)

func RegRemoveScript

func RegRemoveScript(in string) string

func Remove

func Remove(filename string) (err error)

Remove 安全删除文件

func ReplaceInvalidRealName

func ReplaceInvalidRealName(name string) string

func SecretKeyMask

func SecretKeyMask(secretKey string) (str string)

func SetByFields

func SetByFields(aExt interface{}, colName string, dstValue interface{}) error

func SetupSignalHandler

func SetupSignalHandler(shutdownFunc func())

SetupSignalHandler setup signal handler

func Sha1

func Sha1(data string) string

func Sha256

func Sha256(data string) string

func SimpleHttpClient

func SimpleHttpClient(reqMethod string, reqUrl string, reqHeaders map[string]string, reqBody string, timeoutConf HttpTimeout) (statusCode int, respHeader http.Header, respBody []byte, err error)

SimpleHttpClient Deprecated: please use more advanced go-resty instead see: https://github.com/go-resty/resty

func SimpleNumStr2Num

func SimpleNumStr2Num(s string) int

func SnakeString

func SnakeString(s string) string

Snake string, XxYy to xx_yy , XxYY to xx_yy

func SqlPlaceholderWithArray

func SqlPlaceholderWithArray(length int) string

func Str2Float

func Str2Float(s string) (f float32, err error)

func Str2Float64

func Str2Float64(s string) (f float64, err error)

func Str2Int

func Str2Int(str string) (int, error)

func Str2Int64

func Str2Int64(str string) (int64, error)

func StrReplace

func StrReplace(origin string, search []string, replace string) (s string)

StrReplace 在 origin 中搜索 search 组,替换成 replace

func StrTenThousand2MoneyMul100

func StrTenThousand2MoneyMul100(money string) int64

func StrTrim

func StrTrim(str string) string

func Stringify

func Stringify(obj interface{}) string

func StringsContains

func StringsContains(array []string, val string) (index int)

func StripSlashes

func StripSlashes(str string) string

func SubString

func SubString(s string, pos, length int) string

字串截取

func SubStringByPos

func SubStringByPos(s string, sPos, ePos int) string

字串截取

func TrimRealName

func TrimRealName(name string) string

func TrimTags

func TrimTags(s string) string

func URLBase64Decode

func URLBase64Decode(data string) ([]byte, error)

url base64解码

func URLBase64Encode

func URLBase64Encode(data []byte) string

url base64编码

func Unicode

func Unicode(rs string) string

func UnixMillis

func UnixMillis() int64

UnixMillis 取当前系统时间的毫秒

func UnixMsec2Date

func UnixMsec2Date(um int64, layout string) string

func UrlDecode

func UrlDecode(data string) (string, error)

url 解码

func UrlEncode

func UrlEncode(data string) string

url 编码

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

func VerifyBirthday

func VerifyBirthday(birthday string) bool

func VerifyEmail

func VerifyEmail(email string) bool

VerifyEmail

func VerifyMobile

func VerifyMobile(mobile string) bool

VerifyMobile,国内手机号

Types

type HttpTimeout

type HttpTimeout struct {
	DialTimeout           int
	DialKeepAlive         int
	TLSHandshakeTimeout   int
	ResponseHeaderTimeout int
	ExpectContinueTimeout int
	Timeout               int
}

func DefaultHttpTimeout

func DefaultHttpTimeout() HttpTimeout

func SetHttpTimeout

func SetHttpTimeout(dialTimeout, dialKeepAlive, tlsHandshakeTimeout, responseHeaderTimeout, expectContinueTimeout, timeout int) HttpTimeout

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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