[DEV] add error and test and example
This commit is contained in:
parent
46229c5edf
commit
c2309da7b0
17
error.go
Normal file
17
error.go
Normal 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
1
example/model/dao/dao.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package dao
|
22
example/model/model.go
Normal file
22
example/model/model.go
Normal 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")
|
||||||
|
}
|
0
example/model/tables/t_user/t_user.go
Normal file
0
example/model/tables/t_user/t_user.go
Normal file
1
model_test.go
Normal file
1
model_test.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package model
|
Loading…
Reference in New Issue
Block a user