1 Star 4 Fork 2

tym_hmm / go-helper

2024-01-19 22:07
天蝎儿

#增加总数number 拆分

/*
 * 将一个总数(sum) 拆分成n组 最小数为m
 * 随机分配 每次个数和为总数
 * ex:
 * sum: 20(总合) , n:2(两组), m:1(最小数1)
 * out:
 * random out: [18 2]
 * random out: [19 1]
 * random out: [17 3]
 * random out: [8 12]
 * @param n int 拆分成数量
 * @param sum int 总和
 * @param m int 最小数
 */
func splitSumRandGroup(n int, sum int, m int) []int 


/**
 * 将一个数生成连接的数并分组
 * @param total 总数
 * @param groupSize 每组大小
 * [1 2 3 4 5]
 * [6 7 8 9 10]
 * [11 12 13 14 15]
 * [16 17 18 19 20]
 */
func SplitSumContinuousGroup(total int, groupSize int) [][]int 

最后提交信息为: 增加总数拆分
2023-06-25 13:10
天蝎儿

#增加字符串截取向右开始

SubStr(tradeNumber, start, end)

example:

var tradeNumber = "123456789"

# 中间截取
middle, _ := SubStr(tradeNumber, 2, 7)
# 开始截取
start, _ := SubStr(tradeNumber, 2, -1)
# 向右截取
end, _ := SubStr(tradeNumber, -1, 4)

out:

middle => 34567
start => 3456789
end => 6789
最后提交信息为: 修复字符串截取
2023-06-16 09:26
天蝎儿

#去除异常日志

最后提交信息为: 去除
2023-05-14 15:39
天蝎儿

#增加日志

最后提交信息为: 日志输出
2023-05-14 15:24
天蝎儿

#增加try catch 异常输出

最后提交信息为: 异常日志输出
2023-05-11 15:42
天蝎儿

#增加字符串截取

@param str string 原字符串
@param start int 开始位置
@param end int 结束位置
StringHelper.SubStr(str string, start int, end int)(string, error)
最后提交信息为: 增加字符串截取
2023-03-12 00:30
天蝎儿

#增加ip处理

IpHelper

//Ip4转 uint32
Ip2long(ipstr string) uint32
//uint64转ip4
Long2ip(ipLong uint32) string

//获取客户端ip
GetRemoteIp(req *http.Request) string
最后提交信息为: 修复ip转字符串类型错误
2023-02-27 22:36
天蝎儿

#修复aes加密。数据为空问题

最后提交信息为: 修复aes数据问题
2023-02-22 16:57
天蝎儿

#增加小数长度获取

最后提交信息为: 增加float长度获取
2023-02-22 16:18
天蝎儿

#修改数字精度处理目录
PrecisionHelper\Precision.go 移动到 => PrecisionHelper\Precision\Precision.go

最后提交信息为: 修改数字精度处理包名
2023-02-22 10:42
天蝎儿

#增加 PrecisionHelper 整数、浮点数等精度处理, 包含运算精度

price, err := PrecisionHelper.NewFromString("136.02")
if err != nil {
    panic(err)
}
quantity := PrecisionHelper.NewFromInt(3)
fee, _ := PrecisionHelper.NewFromString(".035")
taxRate, _ := PrecisionHelper.NewFromString(".08875")

subtotal := price.Mul(quantity)

preTax := subtotal.Mul(fee.Add(PrecisionHelper.NewFromFloat(1)))

total := preTax.Mul(taxRate.Add(PrecisionHelper.NewFromFloat(1)))

fmt.Println("price:", price)                            // price: 136.02
fmt.Println("quantity:", quantity)                      // quantity: 3
fmt.Println("fee:", fee)                                // fee: 0.035
fmt.Println("taxRate:", taxRate)                        // taxRate: 0.08875
fmt.Println("Subtotal:", subtotal)                      // Subtotal: 408.06
fmt.Println("Pre-tax:", preTax)                         // Pre-tax: 422.3421
fmt.Println("Taxes:", total.Sub(preTax))                // Taxes: 37.482861375
fmt.Println("Total:", total)                            // Total: 459.824961375
fmt.Println("Tax rate:", total.Sub(preTax).Div(preTax)) // Tax rate: 0.08875

fmt.Println(PrecisionHelper.NewFromFloat(123.123123123123).String()) //123.123123123123
fmt.Println(PrecisionHelper.NewFromFloat(.123123123123123).String()) //0.123123123123123
fmt.Println(PrecisionHelper.NewFromFloat(-1e13).String())            //-10000000000000
2023-01-11 23:15
天蝎儿

#增加获取当前时间,月的第一天后最后一天

times, errs := TimeHelper.TimeParseDate("2020-02-29")
	if errs != nil {
		t.Errorf("error %+v", errs)
		return
	}
	ds, err := TimeHelper.GetTimeDateMonthBeginAndEnd(times)
	if err != nil {
		t.Errorf("error %+v", err)
	} else {
		t.Logf("xxx %+v", ds)
	}
2022-11-23 00:44
天蝎儿

#增加获取东八区获取

#获取东八区时区
TimeHelper.GetCstZone()
最后提交信息为: 增加东八区时区获取
2022-11-17 15:59
天蝎儿

#增加TimerHelper返回秒级时间戳
#增加解析时间戳到TimerHelper返回时间

//TimerHelper返回秒级时间戳
TimeHelper.NewNowTime().ToUnix()

#解析时间戳
TimeParseUnixSecondToDate(unxitmeTime int64)(*TimeHelper, error)

var unixTime in64 = 1531293019
th,_:=Timelper.TimeParseUnixSecondToDate(unixTime)
th.ToAll()
2022-11-16 18:09
天蝎儿

#增加sha1加密
#增加TimeHelper返回毫秒

#sha1
var str = "11111"
enStr:=Sha1.Sah1(str)

#返回毫秒
TimeHelper.NewNowTime().ToMillisecond()
最后提交信息为: 增加time返回毫秒
2022-11-08 23:24
天蝎儿

#增加异常抛出是否显示日志

ThrowLog(code int, message string, param ...interface{})
Throw(code int, message string, param ...interface{})
最后提交信息为: 修改throw 是否显示日志输出
2022-11-07 16:54
天蝎儿

#增加随机数中自定义随机因子

RandomAroundFloat64Seed(seed int64, min, max float64) float64

RandomAroundIntSeed(seed int64, min, max int)  (int, error)

RandomAroundInt32Seed(seed int64, min, max int32)
``
最后提交信息为: 增加随机数自定义随机因子
2022-11-05 18:46
天蝎儿

#增加字符串月的解析

TimeHelper.TimeParseMonth(s string)(time.Time, error)
最后提交信息为: 增加日期解析月
2022-10-31 19:01
天蝎儿

#修复golang 官方包中time.AddDate() 年月加减问题

//日期加减
TimeHelper.AddDate(time time.Time, year int, montth int, day int)

//获取当前月的上一个月
ts, _ := TimeHelper.TimePare("2020-03-31 23:59:59")
th := TimeHelper.NewTime(ts)
last := th.GetSubMonth(-1)
t.Logf("月份:%s", last)

lastTime := th.GetSubMonthTime(-1)
t.Logf("月份:%s", lastTime)
最后提交信息为: 修复获取上个月的问题
2022-10-31 18:30
天蝎儿

#修复timehlper 中时区为东八区

最后提交信息为: 增加时间时区 默认为东八区
Go
1
https://gitee.com/tym_hmm/go-helper.git
git@gitee.com:tym_hmm/go-helper.git
tym_hmm
go-helper
go-helper

搜索帮助