utils

package
v0.0.0-...-dae8c3a Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package utils @Author: cobol @Comment: 时间相关工具 - 注意: 考虑到时区因素, 所有时间都是UTC时间

Index

Constants

View Source
const BaseTimeMicro = 4070880000

BaseTimeMicro 默认微秒累加 - 2099-01-01 00:00:00

View Source
const IP_V6_URL = "https://ip.zxinc.org/api.php?type=json&ip="

IP_V6_URL 用于临时处理ipv6的数据库

View Source
const SecretKey = "0jas3^128*@#*Ls]/<M';sdf3Dnbm?@$"

SecretKey 后台加密用到的KEY, 切勿改动

View Source
const ServerKey = "a!k@9#d%9*&aDQK-=bv<M+3456*8c0}@"

ServerKey 服务器端的key

Variables

View Source
var Letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678")

Letters 默认的可用字符

View Source
var McryptLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

McryptLetters 用于生成随机字符串的值

View Source
var McryptLettersLower = []rune("abcdefghijklmnopqrstuvwxyz0123456789")

McryptLettersLower 用于生成随机字符串的值

Functions

func CurrentTime

func CurrentTime() time.Time

CurrentTime 标准获取当前时间 - 考虑时区因素

func Date

func Date() (int, int, int)

Date 得到当前的年/月/日

func DateOf

func DateOf(now time.Time) (int, int, int)

DateOf 得到当前的年/月/日

func Dec2Hex

func Dec2Hex(val int) string

Dec2Hex 十进制转16进制

func DecodeUserId

func DecodeUserId(icode string) (int, error)

DecodeUserId 解码用户编号

func EncodeUserId

func EncodeUserId(uid uint64) string

EncodeUserId 编码用户编号

func EncryptedPassword

func EncryptedPassword(pwd string) string

EncryptedPassword 生成用户密码

func GenVCode

func GenVCode() string

GenVCode 验证码

func GenerateRangeNum

func GenerateRangeNum(min, max int) int

GenerateRangeNum 随机生成指定范围的数字比如6-9

func GetAreaByIp

func GetAreaByIp(ipAddress string) string

GetAreaByIp 依据IP得到地区

func GetBillNo

func GetBillNo(prefix string, n int) string

GetBillNo 生成订单号 字符串型

func GetBillNoInt

func GetBillNoInt(prefix string, n int) string

GetBillNoInt 生成订单号数字

func GetDateTimeByUnix

func GetDateTimeByUnix(ts int64) string

GetDateTimeByUnix 通过unix获取时间 - 秒

func GetDateTimeByUnixMicro

func GetDateTimeByUnixMicro(ts int64) string

GetDateTimeByUnixMicro 通过unix获取时间 - 微秒

func GetDayEnd

func GetDayEnd() time.Time

GetDayEnd 本日结束时间

func GetDayStart

func GetDayStart() time.Time

GetDayStart 本日开始时间

func GetFieldByStruct

func GetFieldByStruct(v interface{}, field string) string

GetFieldByStruct 获取结构体字段

func GetIpV6AreaFromUrl

func GetIpV6AreaFromUrl(ipAddress string) string

GetIpV6AreaFromUrl 从url当中得到ipv6结果

func GetLastMonthEnd

func GetLastMonthEnd() time.Time

GetLastMonthEnd 得到上月最后一天

func GetLastMonthStart

func GetLastMonthStart() time.Time

GetLastMonthStart 得到上月第一天

func GetLastWeekEnd

func GetLastWeekEnd() time.Time

GetLastWeekEnd 上周最后一天

func GetLastWeekStart

func GetLastWeekStart() time.Time

GetLastWeekStart 上周第一天

func GetMonthEnd

func GetMonthEnd() time.Time

GetMonthEnd 得到本月最后一天

func GetMonthStart

func GetMonthStart() time.Time

GetMonthStart 得到本月第一天

func GetPassword

func GetPassword(password, secret string) string

GetPassword 生成密码

func GetRandString

func GetRandString(n uint) string

GetRandString 生成随机字符串

func GetRealPass

func GetRealPass(password, salt string) string

GetRealPass 依据password/salt生成密码

func GetSecret

func GetSecret() string

GetSecret 随机生成密钥

func GetTimeByUnix

func GetTimeByUnix(ts int64) time.Time

GetTimeByUnix 通过unix获取时间 - 秒

func GetTimeByUnixMicro

func GetTimeByUnixMicro(int64Time int64) time.Time

GetTimeByUnixMicro 通过unix获取时间 - 微秒

func GetTodayEnd

func GetTodayEnd() time.Time

GetTodayEnd 今日结束时间

func GetTodayStart

func GetTodayStart() time.Time

GetTodayStart 今日开始时间

func GetUnixByDateTime

func GetUnixByDateTime(dateTime string) int64

GetUnixByDateTime 通过时间获取时间

func GetUnixMicroByDateTime

func GetUnixMicroByDateTime(dateTime string) int64

GetUnixMicroByDateTime GetTimeByDateTime 通过时间获取时间

func GetWeekEnd

func GetWeekEnd() time.Time

GetWeekEnd 本周最后一天

func GetWeekStart

func GetWeekStart() time.Time

GetWeekStart 本周第一天

func GetYesterdayEnd

func GetYesterdayEnd() time.Time

GetYesterdayEnd 昨日结束时间

func GetYesterdayStart

func GetYesterdayStart() time.Time

GetYesterdayStart 昨日开始时间

func GoID

func GoID() int

GoID 协程编号 注意: 以获取调用栈的方式获取id, 性能堪忧, 请尽量不要使用此方法

func Hex2Dec

func Hex2Dec(val string) (int, error)

Hex2Dec 十六进制转十进制

func HttpGet

func HttpGet(url string) (string, error)

HttpGet 获取http内容

func HttpPost

func HttpPost(url string, requestBody []byte, bodyType int) (string, error)

HttpPost 0 json 1 form

func InSlice

func InSlice[T int8 | uint8 | int16 | uint16 | int32 | uint32 | int | uint | int64 | uint64 | float32 | float64 | string | bool](arr []T, ele T) bool

InSlice 字符串序列是否包含

func IsIPv4

func IsIPv4(ipAddress string) bool

IsIPv4 是否ipv4

func IsIPv6

func IsIPv6(ipAddress string) bool

IsIPv6 check if the string is an IP version 6.

func LoadIpV6Data

func LoadIpV6Data()

LoadIpV6Data 加载ipv6数据相关信息

func MD5

func MD5(str string) string

MD5 生成md5的值

func MD5Str

func MD5Str(data string) string

MD5Str md5加密

func MessageChannel

func MessageChannel(phone string, code string, tmp int) error

MessageChannel 首选短信通道

func MessageChannelSecond

func MessageChannelSecond(phone string, code string, tmp int) error

MessageChannelSecond 次用短信通道

func MessageChannelSpare

func MessageChannelSpare(phone string, code string, tmp int) error

MessageChannelSpare 备用短信通道

func MicroToSecond

func MicroToSecond(micro int64) int64

MicroToSecond 转换为秒数

func Now

func Now() time.Time

Now 标准获取当前时间

func NowMicro

func NowMicro() int64

NowMicro 当前微秒

func NowMills

func NowMills() int64

NowMills 得到毫秒

func NowSecs

func NowSecs() int64

NowSecs 得到秒

func PKCS7Padding

func PKCS7Padding(ciphertext []byte) []byte
	CBC加密 按照golang标准库的例子代码
 	不过里面没有填充的部分,所以补上

PKCS7Padding 使用PKCS7进行填充,IOS也是7

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) []byte

PKCS7UnPadding 补齐

func RandInt64

func RandInt64(min, max int64) int64

RandInt64 随机int64

func RandString

func RandString(n int) string

RandString 生成随机字符串

func SHA256

func SHA256(v string) string

func SecondToMicro

func SecondToMicro(second int64) int64

SecondToMicro 秒转为微秒

func Secret

func Secret() string

Secret 得到一个Salt

func SendEmail

func SendEmail(email, title, content string) error

SendEmail 发送邮件

func SendSMS

func SendSMS(phone string, code string, tmp int, channel string) error

SendSMS 发送验证码短信

func SetStructFieldByJsonName

func SetStructFieldByJsonName(ptr interface{}, fields map[string]string)

SetStructFieldByJsonName 将hgetall出来的map[string]string转换成对应的结构体

func StructureToMap

func StructureToMap(request interface{}, tagInfo string) map[string]interface{}

StructureToMap 结构转map,因为struct不能循环,map可以.

func StructureToMapNew

func StructureToMapNew(item interface{}) map[string]interface{}

StructureToMapNew 结构转map,因为struct不能循环,map可以.

func StructureToSlice

func StructureToSlice(request interface{}, tagInfo string) []string

StructureToSlice 结构转map,因为struct不能循环,map可以.

func Time

func Time() time.Time

Time 标准获取当前时间 - 考虑时区因素

func Timestamp

func Timestamp() int64

Timestamp 标准获取当前时间

func VerifyPassword

func VerifyPassword(pwd, enPwd string) bool

VerifyPassword 校验密码

func WriteIpV6Data

func WriteIpV6Data(ipAddress, area string)

WriteIpV6Data 将ipv6数据写入到文件当中

Types

type ZxincV6

type ZxincV6 struct {
	Code int `json:"code"`
	Data struct {
		Country string `json:"country"`
		Ip      struct {
			End   string `json:"end"`
			Start string `json:"start"`
		} `json:"ip"`
		Local    string `json:"local"`
		Location string `json:"location"`
		Myip     string `json:"myip"`
	} `json:"data"`
}

ZxincV6 从zxinc网址拿来下的数据结构

Jump to

Keyboard shortcuts

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