[DEV] add error and test and example

This commit is contained in:
bryan 2025-04-27 14:44:50 +08:00
parent 46229c5edf
commit c2309da7b0
5 changed files with 41 additions and 0 deletions

17
error.go Normal file
View File

@ -0,0 +1,17 @@
package model
import "strings"
func IsDuplicateError(err error) bool {
if err == nil {
return false
}
var errstr = strings.ToLower(err.Error())
if strings.HasPrefix(errstr, "error 1062 (23000): duplicate entry") {
return true
} else if strings.Contains(errstr, "error") && strings.Contains(errstr, "duplicate entry") {
return true
}
return false
}

1
example/model/dao/dao.go Normal file
View File

@ -0,0 +1 @@
package dao

22
example/model/model.go Normal file
View File

@ -0,0 +1,22 @@
package model
import (
"qoobing.ai/payserver/config"
"qoobing.com/gomod/log"
"qoobing.com/gomod/model"
)
var (
Db = model.Db
DbOf = model.DbOf
Redis = model.Redis
RedisPool = model.RedisPool
RedisPoolOf = model.RedisPoolOf
)
func init() {
cfg := config.Instance()
model.Init("pay", &cfg.PayDb)
model.Init("pay", &cfg.PayRedis)
log.Infof("model initlized")
}

View File

1
model_test.go Normal file
View File

@ -0,0 +1 @@
package model