包名字怎么这么长啊
包
uuid
https://github.com/segmentio/ksuid
iter
https://github.com/bradfitz/iter
doc
json
Get JSON values quickly
https://github.com/tidwall/gjson
jinzhu/copier
结构体赋值
https://github.com/jinzhu/copier
imdario/mergo
结构体赋值到 map
https://github.com/imdario/mergo
时间戳
当前秒级时间戳
1 2 3
| func Now() int64 { return time.Now().Unix() }
|
当前毫秒级时间戳
1 2 3
| func NowNano() int { return int(time.Now().UnixNano() / 1e6) }
|
今日凌晨时间戳
1 2 3 4 5
| func GetTodayZeroTimestamp() int { t := time.Now() tm1 := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) return int(tm1.Unix()) }
|
随机数
1 2 3 4
| func GenerateZeroToNineRandomNumber(max int) int { rand.Seed(time.Now().UnixNano()) return rand.Intn(max) }
|
科学计数 float 转 int
1 2 3 4 5 6 7 8
| var newNum float64 numStr := "1.57103592E9" _, err := fmt.Sscanf(numStr, "%e", &newNum) if err != nil { panic(err) return } num := fmt.Sprintf("%.f", newNum)
|