libtools

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: Apache-2.0 Imports: 55 Imported by: 0

README

libtools

common golang lib tools

Documentation

Index

Constants

View Source
const (
	SecondAHour      int64 = 3600
	MillsSecondAHour       = SecondAHour * 1000
	SecondADay       int64 = 86400
	MillsSecondADay        = SecondADay * 1000
	MillsSecondAYear       = MillsSecondADay * 365
)
View Source
const (
	AesPKCS5 int = iota
	AesPKCS7
)
View Source
const (
	HttpMethodGet  string = "GET"
	HttpMethodPOST string = "POST"
)
View Source
const (
	CHAR_SET               = "UTF-8"
	BASE_64_FORMAT         = "UrlSafeNoPadding"
	RSA_ALGORITHM_KEY_TYPE = "PKCS8"
	//RSA_ALGORITHM_SIGN     = crypto.SHA256
	RSA_ALGORITHM_SIGN = crypto.SHA1
)
View Source
const (
	ProductDomain = "https://api.4reasons.cn"
	DevDomain     = "https://4reasons-api.yichehuzhu.com"

	ProductH5Domain = "https://h5.yichehuzhu.com"
	DevH5Domain     = "https://h5-dev.yichehuzhu.com"
)
View Source
const (
	AesCBCIV string = "7816a1762a9a145c24726ea5790fe39a"
)
View Source
const EmptyRecord string = "-"
View Source
const MinWithdrawAmount int64 = 600

Variables

This section is empty.

Functions

func AbsInt64

func AbsInt64(num int64) int64

func AddSlashes

func AddSlashes(str string) string

func AesDecrypt

func AesDecrypt(crypted, key []byte) []byte

func AesDecryptCBC

func AesDecryptCBC(ciphertext string, key string, iv string) (string, error)

func AesDecryptCBCV2

func AesDecryptCBCV2(ciphertext string, key string, iv string) (string, error)

func AesDecryptUrlCode

func AesDecryptUrlCode(ciphertext string, key string, iv string) (string, error)

func AesEncryptCBC

func AesEncryptCBC(src string, key string, iv string) (string, error)

包装过的简单加密函数

func AesEncryptCBCV2

func AesEncryptCBCV2(src string, key string, iv string) (string, error)

func AesEncryptECB

func AesEncryptECB(src, key string) string

func AesEncryptECBUrlEncode

func AesEncryptECBUrlEncode(src, key string) string

func AppNumVersion

func AppNumVersion(appVersion string) int64

4位字符串版本 1.1234.1234.1234

func AppNumVersion3

func AppNumVersion3(appVersion string) int64

3 位版本号 1.2.3

func ArrayToString

func ArrayToString(a interface{}, delim string) (newStr string)

将slice 转化成字符串 []int{1, 2, 3, 4, 5} => 1,2,3,4,5 或 []string{"1", "2", "3", "4", "5"} => 1,2,3,4,5 "AAA bbb" 转为 AAA,bbb 其他类型返回空字符串

func Base64Decode

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

base64解码

func Base64Encode

func Base64Encode(data []byte) string

base64编码

func Base64URLDecode

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

func Base64UrlSafeEncode

func Base64UrlSafeEncode(source []byte) string

func BaseDayOffset

func BaseDayOffset(baseDay int64, offset int64) (um int64)

* 基于指定时间的偏移量

func BasicAuth

func BasicAuth(username, password string) string

func BuildEsGeoLocation

func BuildEsGeoLocation(lng, lat string) string

func BuildFaceBookUserAvatar

func BuildFaceBookUserAvatar(userID string) string

func BuildFileHashName

func BuildFileHashName(localFile string) (hashDir, hashName, fileMd5 string, err error)

BuildFileHashName 创建本地文件的hash名

func BuildHashName

func BuildHashName(fileMd5, suffix string) (hashDir, hashName string)

func BuildOpMsg

func BuildOpMsg(origin string, msg string, OpBy int64) string

func BuildServiceFeeBody

func BuildServiceFeeBody(amount int64) (body types.ServiceFeeBody)

func BuildUploadFileHashName

func BuildUploadFileHashName(buf []byte, suffix string) (hashDir, hashName, fileMd5 string)

为app端上传文件生成hash文件名

func BuildWithdrawBody

func BuildWithdrawBody(total int64) (body types.WithdrawBody)

func CKEditorFullHtml

func CKEditorFullHtml(content string) string

func CaculateTimeZone

func CaculateTimeZone(lon float64) string

caculateTimeZone计算时区

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

通过反射更改结构体的值

func CheckRequiredParameter

func CheckRequiredParameter(parameter map[string]interface{}, requiredParameter map[string]bool) bool

CheckRequiredParameter 通用的检查必要参数的方法,只检测参数存在,不关心参数值

func ClearOnSignal

func ClearOnSignal(handler func())

func CoinDisplay

func CoinDisplay(money int64) string

func CoinDisplayFloat64

func CoinDisplayFloat64(money int64) float64

func CompareEquals

func CompareEquals(val1, val2 float64) bool

func ContainNumber

func ContainNumber(str string) (valid bool)

func ConvertTime2Secs

func ConvertTime2Secs(str string) int

*

13:23

func DBDriver

func DBDriver() string

func Date2UnixMsec

func Date2UnixMsec(dateStr, layout string) int64

func DateMHSZ

func DateMHSZ(timestamp int64) string

func DateParseYMDHMS

func DateParseYMDHMS(dates string) int64

DateParseYMDHMS 解析 YYYY-MM-DD HH:MM:SS 格式的时间串为Unix时间戳

func DecimalMoneyMul100

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

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

func Decrypter

func Decrypter(crypted []byte, key []byte, iv []byte, paddingType int) ([]byte, error)

解密

func Default7DaysTimeRange

func Default7DaysTimeRange() string

func DefaultReqHeaders

func DefaultReqHeaders() (reqHeaders map[string]string)

func DefaultToday

func DefaultToday() string

func DefaultTodayMHS

func DefaultTodayMHS() string

func DefaultTodayTimeRange

func DefaultTodayTimeRange() string

func DefaultYesterday

func DefaultYesterday() string

func DefaultYesterdayTimeRange

func DefaultYesterdayTimeRange() string

func DetectFileByteType

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

func DetectFileType

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

func DisplayByKey4Map

func DisplayByKey4Map(key interface{}, m map[interface{}]interface{}) (html string)

func DivideRedPacket

func DivideRedPacket(count, amount int64)

func DoubleAverage

func DoubleAverage(count, amount int64) int64

二倍均值算法,count剩余个数,amount剩余金额

func Encrypter

func Encrypter(source []byte, key []byte, iv []byte, paddingType int) ([]byte, error)

加密

func EnvDisplay

func EnvDisplay() string

func EsGeoLocation2LngLat

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

func Escape

func Escape(html string) string

func ExcelConvertToFormatDay

func ExcelConvertToFormatDay(excelDaysString string) string

func Exists

func Exists(file string) bool

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

func ExtractUrls

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

func FeeRateTransform

func FeeRateTransform(origin float64) (after int64)

func FieldByName

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

通过反射取得特定字段

func FileDownload

func FileDownload(fileName, url string) (realFileName string, err error)

func FixCountNum

func FixCountNum(in int) int

func Float2Str

func Float2Str(f float32) string

func Float64TruncateWith2

func Float64TruncateWith2(num float64) (after float64, err error)

func Float642Str

func Float642Str(f float64) string

func FullStack

func FullStack() string

func Gbk2Utf8

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

func GenOpenAvatar

func GenOpenAvatar(openAvatar string) (avatar string)

func GenRsaKey

func GenRsaKey(publicKeyWriter, privateKeyWriter io.Writer, keyLength int) error

生成密钥对

func GenerateMobileCaptcha

func GenerateMobileCaptcha(length int) string

! 手机验证在4-8位之间

func GenerateRandom

func GenerateRandom(min, max int) int

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

func GenerateRandom64

func GenerateRandom64(min, max int64) int64

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

func GenerateRandomStr

func GenerateRandomStr(length int) string

func GeoIpCityEn

func GeoIpCityEn(ipOrigin string) string

func GeoIpCityZhCN

func GeoIpCityZhCN(ipOrigin string) string

func GeoipISOCountryCode

func GeoipISOCountryCode(ipOrigin string) string

ip取ISO国家码

func GetCurrentEnv

func GetCurrentEnv() string

func GetDate

func GetDate(timestamp int64) string

func GetDateFormat

func GetDateFormat(timestamp int64, format string) string

func GetDateMH

func GetDateMH(timestamp int64) string

func GetDateMHS

func GetDateMHS(timestamp int64) string

func GetDateParse

func GetDateParse(dates string) int64

GetDateParse 用于跑批, 或者需要以 UTC时区为基准的时间解析

func GetDateParseBackend

func GetDateParseBackend(dates string) int64

GetDateParseBackend 所有后台使用

func GetDateParses

func GetDateParses(dates string) int64

GetDateParse 用于跑批, 或者需要以 UTC时区为基准的时间解析

func GetDateRange

func GetDateRange(begin, end int64) int64

func GetDateRangeMillis

func GetDateRangeMillis(begin, end int64) int64

func GetDateTimeBy5step

func GetDateTimeBy5step(t int64) int64

* 获取过去时中最近的5分数

func GetDateTimeByBegin

func GetDateTimeByBegin(t int64) int64

* 获取一天的0点0分0秒

func GetDateTimeParseBackend

func GetDateTimeParseBackend(dates string) int64

func GetDistance

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

返回单位为:米

func GetFileExt

func GetFileExt(filename string) (suffix string)

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

func GetGuid

func GetGuid() string

Guid方法

func GetHourDateTime

func GetHourDateTime(t int64, h int) int64

* 获取一天的固定时间的毫秒数 h 24

func GetIntKeysOfMap

func GetIntKeysOfMap(mymap map[int]string) (keys []int)

func GetLocalUploadPrefix

func GetLocalUploadPrefix() string

func GetMP4Duration

func GetMP4Duration(reader io.ReaderAt) (lengthOfTime uint32, err error)

GetMP4Duration 获取视频时长,以秒计

func GetMonth

func GetMonth(timetag int64) int64

返回的单位是秒

func GetMonthRange

func GetMonthRange(timestamp int64) (begin, end int64)

* 获取一个月的周期时间(毫秒)

func GetS3Key

func GetS3Key(fileName string) string

func GetTime

func GetTime(timestamp int64) string

* 获取时间计数

func GetTimeByTodaySecs

func GetTimeByTodaySecs(secs int) string

func GetUnixMillis

func GetUnixMillis() int64

取当前系统时间的毫秒

func GetUnixMillisByTime

func GetUnixMillisByTime(t time.Time) int64

func GitRevParseHead

func GitRevParseHead() string

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 InIntSlice

func InIntSlice(v int64, sl []int64) bool

InIntSlice checks given string in string slice or not.

func InSlice

func InSlice(v string, sl []string) bool

InSlice checks given string in string slice or not.

func InSliceIface

func InSliceIface(v interface{}, sl []interface{}) bool

InSliceIface checks given interface in interface slice.

func IndexNumber

func IndexNumber(index int) int

* 将数组默认的0,转为1

func Int2Str

func Int2Str(number int) string

func Int642Str

func Int642Str(number int64) string

func InternalApiDomain

func InternalApiDomain() string

func InternalH5Domain

func InternalH5Domain() string

func IntsSliceToWhereInString

func IntsSliceToWhereInString(intsSlice interface{}) (s string, err error)

IntsSliceToWhereInString 将状态或者IDs集合转换为string interface{}支持所有int, int8 etc.: %d

func IsDir

func IsDir(file string) bool

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

func IsFile

func IsFile(file string) bool

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

func IsInMap

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

IsInMap template辅助方法 key 是否在map中

func IsInMapV2

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

func IsIndonesiaName

func IsIndonesiaName(name string) (valid bool)

IsIndonesiaName 判断是否是合法的印尼名字

func IsInternalIPV1

func IsInternalIPV1(ip string) bool

IsInternalIPV1 超简算法

func IsNumber

func IsNumber(str string) (valid bool)

IsNumber 判断是否都是数字

func IsProductEnv

func IsProductEnv() bool

func IsStructContainsField

func IsStructContainsField(obj interface{}, field string) bool

IsStructContainsField 判断结构体是否包含给定的字段 方法有点脆弱,不能传结构体指针!!!

func IsValidIndonesiaMobile

func IsValidIndonesiaMobile(mobile string) (yes bool, err error)

IsValidIndonesiaMobile 是否是印尼的有效电话号 08 开头, 10-13位数字, 2018.08,有13位手机号段了 2018.11 增加15位手机号判断

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 LocalHashDir

func LocalHashDir(hashDir string) string

生成本地hash目录

func LocalYearMonth

func LocalYearMonth(timestamp int64) string

func Long2IP4

func Long2IP4(ipLong int64) string

func MDateMH

func MDateMH(timestamp int64) string

格式化毫秒时间

func MDateMHS

func MDateMHS(timestamp int64) string

毫秒,输出本地时间

func MDateMHSBeijing

func MDateMHSBeijing(timestamp int64) string

毫秒,输出北京时间

func MDateMHSLocalDate

func MDateMHSLocalDate(timestamp int64) string

func MDateMHSLocalDateAllNum

func MDateMHSLocalDateAllNum(timestamp int64) string

func MDateUTC

func MDateUTC(timestamp int64) string

毫秒

func Map2Form

func Map2Form(param map[string]interface{}, encode bool) (form string)

func Map2struct

func Map2struct(data map[string]interface{}, result interface{}) error

func MapSortKeyStr

func MapSortKeyStr(params map[string]interface{}) string

func MarshalPKCS8PrivateKey

func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte

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 MobileDesensitization

func MobileDesensitization(src string) (dst string)

手机号脱敏处理(只保留前两位和后四位,中间的每个字符都替换为"*") 例如:08123456789 改为 08*****6789, 0812345645678 改为 08*******5678

func MobileFormat

func MobileFormat(mobile string) string

MobileFormat 去除空格,并且不能加拨0或62

func MobileMask

func MobileMask(mobile string) string

func MoneyDisplay

func MoneyDisplay(money int64) string

func MoneyDisplayInt64

func MoneyDisplayInt64(money int64) int64

func MultipartClient

func MultipartClient(reqUrl string, queryString map[string]interface{}, reqHeaders map[string]string, files map[string]string, timeoutConf HttpTimeout) (originByte []byte, httpStatusCode int, err error)

支持post原始多文件上传,同时携带表单数据

func NaturalDay

func NaturalDay(offset int64) (um int64)

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func NicknameMask

func NicknameMask(nickname string) string

func NumberFormat

func NumberFormat(number interface{}) string

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

func PKCS1InitPubKey

func PKCS1InitPubKey(key []byte) (pub *rsa.PublicKey, err error)

func PKCS1InitPubKeyPrivateDecrypt

func PKCS1InitPubKeyPrivateDecrypt(encrypted string, pubkey string, privateKey []byte) (string, error)

func PKCS1RsaEncrypt

func PKCS1RsaEncrypt(data []byte, key []byte) ([]byte, error)

func PKCS1Verify

func PKCS1Verify(key []byte, data string, sign string) error

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

补位

func PKCS5PaddingECB

func PKCS5PaddingECB(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func PKCS5UnPaddingECB

func PKCS5UnPaddingECB(origData []byte) []byte

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) []byte

func ParseCookie

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

func ParseDateRangeToDayRange

func ParseDateRangeToDayRange(dateRange string) (start, end int, err error)

ParseDateRangeToDayRange 将时间范围字符串解析成毫秒时间戳 默认日期分隔符 " - " start, end, err

func ParseDateRangeToDayRangeWithSep

func ParseDateRangeToDayRangeWithSep(dateRange string, splitSep string) (int, int, error)

PareseDateRangeToDayRangeWithSep 将时间范围字符串解析成毫秒时间戳 start, end, err

func ParseMediaBaseInfo

func ParseMediaBaseInfo(rid int64, d []byte) (info types.MediaBaseInfo, 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)

安全删除文件

func ReplaceInvalidRealName

func ReplaceInvalidRealName(name string) string

func RsaDecrypt

func RsaDecrypt(ciphertext string) (string, error)

解密

func RsaEncrypt

func RsaEncrypt(origData []byte) (string, error)

加密

func ScoreDisplay

func ScoreDisplay(score int) string

func SecretKeyMask

func SecretKeyMask(secretKey string) (str string)

func SetByFields

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

func Sha1

func Sha1(data string) string

func Sha256

func Sha256(data string) string

func ShuffleStringList

func ShuffleStringList(list []string)

func Signature

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

Signature 空参数值的参数名参与签名

func Signature4Struct

func Signature4Struct(obj interface{}, secret string) string

func Signature4StructV2

func Signature4StructV2(obj interface{}, secret string) string

func SignatureV2

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

SignatureV2 空参数不参与签名

func SimpleAnonymousHttpClient

func SimpleAnonymousHttpClient(reqMethod string, reqUrl string, reqHeaders map[string]string, reqBody string) ([]byte, int, error)

简单的http客户端,支持POST表单域,但不支持上传文件

func SimpleHttpClient

func SimpleHttpClient(reqMethod string, reqUrl string, reqHeaders map[string]string, reqBody string, timeoutConf HttpTimeout) ([]byte, int, error)

简单的http客户端,支持POST表单域,但不支持上传文件

func SimpleHttpClientCert

func SimpleHttpClientCert(reqMethod string, reqUrl string, reqHeaders map[string]string, reqBody string, timeoutConf HttpTimeout) ([]byte, int, error)

简单的http客户端,支持POST表单域,但不支持上传文件

func SimpleHttpClientV2

func SimpleHttpClientV2(reqMethod string, reqUrl string, reqHeaders map[string]string, reqBody string, timeoutConf HttpTimeout) (header http.Header, body []byte, httpStatusCode int, err error)

func SimpleHttpClientV3

func SimpleHttpClientV3(reqMethod string, reqUrl string, reqHeaders map[string]string, reqBody string, timeoutConf HttpTimeout) ([]byte, int, error)

简单的http客户端,支持POST表单域,但不支持上传文件

func SimpleNumStr2Num

func SimpleNumStr2Num(s string) int

func SliceChunk

func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})

SliceChunk separates one slice to some sized slice.

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})

SliceDiff returns diff slice of slice1 - slice2.

func SliceFilter

func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})

SliceFilter generates a new slice after filter function.

func SliceInt64ToMap

func SliceInt64ToMap(s []int64) map[int64]interface{}

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

func SliceIntersect

func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})

SliceIntersect returns slice that are present in all the slice1 and slice2.

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

SliceMerge merges interface slices to one slice.

func SlicePad

func SlicePad(slice []interface{}, size int, val interface{}) []interface{}

SlicePad prepends size number of val into slice.

func SliceRand

func SliceRand(a []interface{}) (b interface{})

SliceRand returns random one from slice.

func SliceRandList

func SliceRandList(min, max int) []int

SliceRandList generate an int slice from min to max.

func SliceRange

func SliceRange(start, end, step int64) (intslice []int64)

SliceRange generates a new slice from begin to end with step duration of int64 number.

func SliceReduce

func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})

SliceReduce generates a new slice after parsing every value by reduce function

func SliceRepeatVal

func SliceRepeatVal(slice []interface{}) (repeatSlice []interface{})

SliceRepeatVal 获取数组中重复的值

func SliceShuffle

func SliceShuffle(slice []interface{}) []interface{}

SliceShuffle 数组值打乱

func SliceSum

func SliceSum(intslice []int64) (sum int64)

SliceSum sums all values in int64 slice.

func SliceUnique

func SliceUnique(slice []interface{}) (uniqueslice []interface{})

SliceUnique 去掉重复的值

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 Str2TimeByLayout

func Str2TimeByLayout(layout, timeStr string) int64

Str2TimeByLayout 使用layout将时间字符串转unix时间戳(毫秒)

func StrLen

func StrLen(s string) int

func StrReplace

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

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

func StrTenThousand2MoneyMul100

func StrTenThousand2MoneyMul100(money string) int64

func Strim

func Strim(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 Struct2Form

func Struct2Form(obj interface{}, encode bool) (form string)

Struct2Form 结构体转表单

func Struct2FormMap

func Struct2FormMap(obj interface{}, encode bool) map[string]string

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

func Struct2MapString

func Struct2MapString(obj interface{}) map[string]string

func Struct2MapV2

func Struct2MapV2(obj interface{}) map[string]interface{}

func Struct2MapV3

func Struct2MapV3(obj interface{}) map[string]interface{}

Struct2MapV3 结构体转map,有效防止了整型意外转科学记数法

func SubString

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

字串截取

func SubStringByPos

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

字串截取

func ThreeElementExpression

func ThreeElementExpression(status bool, exp1 interface{}, exp2 interface{}) (result interface{})

func TimeNow

func TimeNow() int64

func TimeStrFormat

func TimeStrFormat(timestr, fromFormat, toFormat string, unixtime bool) interface{}

* 从一种时间格式转为另一种 ,或者转为时间戳 * @param timestr 即将处理的时间字符串 * @param fromFormat 当前时间格式 Mon, 02 Jan 2006 MST * @param toFormat 目标时间格式 2006-01-02 15:04:05 * @param fromFormat 当前时间格式 * @param unixtime 为真返回时间戳,否则正常转换时间格式 * @return string []byte

func ToSlice

func ToSlice(arr interface{}) ([]interface{}, error)

ToSlice 转化 泛型为 slice

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

email verify

func VerifyHttpUserAgent

func VerifyHttpUserAgent(userAgent string) bool

func VerifyMobile

func VerifyMobile(mobile string) bool

mobile verify,国内手机号

func WrapGenRsaKey

func WrapGenRsaKey(bits int) (publicKey, privateKey string, err error)

func XPack

func XPack()

Types

type BoxHeader

type BoxHeader struct {
	Size       uint32
	FourccType [4]byte
	Size64     uint64
}

BoxHeader 信息头

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

type Location

type Location struct {
	Latitude  float64
	Longitude float64
	TimeZone  string
}

func GeoIpLocation

func GeoIpLocation(ipOrigin string) Location

type XRsa

type XRsa struct {
	// contains filtered or unexported fields
}

func NewXRsa

func NewXRsa(publicKey []byte, privateKey []byte) (*XRsa, error)

func (*XRsa) PrivateDecrypt

func (r *XRsa) PrivateDecrypt(encrypted string) (string, error)

私钥解密

func (*XRsa) PublicEncrypt

func (r *XRsa) PublicEncrypt(data string) (string, error)

公钥加密

func (*XRsa) Sign

func (r *XRsa) Sign(data string) (string, error)

数据加签

func (*XRsa) Verify

func (r *XRsa) Verify(data string, sign string) error

数据验签

Jump to

Keyboard shortcuts

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