Commit cca51f65 by zhengqiuyun86

nil默认

parent b1bdf6c0
......@@ -9,8 +9,8 @@ import (
func Page(params []page.Param, pageNum int, pageSize int, m interface{}, data interface{}, orderBy string, db *gorm.DB) *page.Data {
var page = page.Data{}
page.PageSize = util.IfInt(pageSize == 0, 10, pageSize)
page.PageNum = util.IfInt(pageNum == 0, 1, pageNum)
page.PageSize = util.If(pageSize == 0, 10, pageSize)
page.PageNum = util.If(pageNum == 0, 1, pageNum)
tx := db.Session(&gorm.Session{PrepareStmt: true})
countTx := tx.Model(&m).Select("count(1)")
if params != nil {
......
package catch
import (
"errors"
"testing"
)
func TestExceptionCatch(t *testing.T) {
defer ExceptionCatch(nil)
panic(errors.New("错误"))
}
package main
import (
"git.168cad.top/zhengqiuyun/rym-util/concurrent/GoroutineExecutor"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/es"
"git.168cad.top/zhengqiuyun/rym-util/log"
......@@ -10,6 +11,12 @@ import (
)
func main() {
orderCode := "2020202021212"
log.Debugf("订单完成通知:%s", orderCode)
GoroutineExecutor.SynDo(func() {
panic("真的错误了")
})
log.Debug("测试")
log.Info("测试")
log.Warn("测试")
......
package util
func IfInt(isTrue bool, a, b int) int {
func If[K any](isTrue bool, a, b K) K {
if isTrue {
return a
}
return b
}
func IfString(isTrue bool, a, b string) string {
if isTrue {
return a
}
return b
func IfNull[K any](a *K, defaultValue K) K {
return If(a == nil, defaultValue, *a)
}
......@@ -13,4 +13,8 @@ func TestContainsForSplitComma(t *testing.T) {
func TestStrval(t *testing.T) {
fmt.Printf("转换内容:%s", GetInterfaceToString(3.10))
var a int
a = If(true, 12, 0)
a = IfNull(&a, 0)
fmt.Printf("结果:%d", a)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment