Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
4551df34b6 | |||
5f5193fd70 | |||
bfe2dd913c | |||
6f28ddd69b |
25
go.mod
25
go.mod
@ -4,7 +4,7 @@ go 1.23.1
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/squirrel v1.5.4
|
github.com/Masterminds/squirrel v1.5.4
|
||||||
github.com/aliyun/alibaba-cloud-sdk-go v1.63.68
|
github.com/aliyun/alibaba-cloud-sdk-go v1.63.71
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/go-pay/gopay v1.5.106
|
github.com/go-pay/gopay v1.5.106
|
||||||
@ -21,14 +21,14 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/bytedance/sonic v1.12.2 // indirect
|
github.com/bytedance/sonic v1.12.6 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.2.0 // indirect
|
github.com/bytedance/sonic/loader v0.2.1 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
github.com/fsnotify/fsnotify v1.8.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/go-pay/crypto v0.0.1 // indirect
|
github.com/go-pay/crypto v0.0.1 // indirect
|
||||||
github.com/go-pay/errgroup v0.0.2 // indirect
|
github.com/go-pay/errgroup v0.0.2 // indirect
|
||||||
@ -37,20 +37,21 @@ require (
|
|||||||
github.com/go-pay/xtime v0.0.2 // indirect
|
github.com/go-pay/xtime v0.0.2 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
github.com/go-playground/validator/v10 v10.23.0 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||||
github.com/goccy/go-json v0.10.3 // indirect
|
github.com/goccy/go-json v0.10.4 // indirect
|
||||||
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
|
||||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.7 // indirect
|
github.com/magiconair/properties v1.8.9 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
@ -61,16 +62,16 @@ require (
|
|||||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
github.com/spf13/afero v1.11.0 // indirect
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
github.com/spf13/cast v1.7.0 // indirect
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
go.uber.org/atomic v1.11.0 // indirect
|
go.uber.org/atomic v1.11.0 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/arch v0.9.0 // indirect
|
golang.org/x/arch v0.12.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
|
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
|
||||||
golang.org/x/net v0.28.0 // indirect
|
golang.org/x/net v0.32.0 // indirect
|
||||||
golang.org/x/sys v0.28.0 // indirect
|
golang.org/x/sys v0.28.0 // indirect
|
||||||
golang.org/x/text v0.21.0 // indirect
|
golang.org/x/text v0.21.0 // indirect
|
||||||
golang.org/x/time v0.8.0 // indirect
|
golang.org/x/time v0.8.0 // indirect
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
package lightCore
|
|
||||||
|
|
||||||
import "code.zhecent.com/gopkg/light-core/pkg/myViper"
|
|
||||||
|
|
||||||
type Start struct {
|
|
||||||
config *Config
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewByConfig(config *Config) *Start {
|
|
||||||
return &Start{config: config}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewByYAML(fileName string, path string) *Start {
|
|
||||||
c := &Config{}
|
|
||||||
myViper.NewSimpleViper(c, "yaml", fileName, path).Apply()
|
|
||||||
return &Start{config: c}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Start) Start() {
|
|
||||||
//校验配置
|
|
||||||
if t.config.App.JwtSecret == "" {
|
|
||||||
panic("App JwtSecret Empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.config.Server.RunMode == "" || t.config.Server.HttpPort == 0 {
|
|
||||||
panic("Server Config Error")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
package mySql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 因为有大量的是简单的通过where查询一条数据的,例如查询某个用户的资料,所以封装这个工具类简化操作,用法与query保持一致
|
|
||||||
type QueryManager struct {
|
|
||||||
tableName string
|
|
||||||
wheres []*QueryManagerWhere
|
|
||||||
errorText string
|
|
||||||
error error
|
|
||||||
}
|
|
||||||
|
|
||||||
type QueryManagerWhere struct {
|
|
||||||
colName string
|
|
||||||
value interface{}
|
|
||||||
emptyCheck bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewQueryManager(tableName string) *QueryManager {
|
|
||||||
return &QueryManager{
|
|
||||||
tableName: tableName,
|
|
||||||
wheres: make([]*QueryManagerWhere, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *QueryManager) SetErrorText(text string) *QueryManager {
|
|
||||||
t.errorText = text
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *QueryManager) Where(colName string, value interface{}) *QueryManager {
|
|
||||||
t.wheres = append(t.wheres, &QueryManagerWhere{
|
|
||||||
colName: colName,
|
|
||||||
value: value,
|
|
||||||
emptyCheck: true,
|
|
||||||
})
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
func (t *QueryManager) WhereRow(colName string, value interface{}, emptyCheck bool) *QueryManager {
|
|
||||||
t.wheres = append(t.wheres, &QueryManagerWhere{
|
|
||||||
colName: colName,
|
|
||||||
value: value,
|
|
||||||
emptyCheck: emptyCheck,
|
|
||||||
})
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *QueryManager) Take(data interface{}) error {
|
|
||||||
if len(t.wheres) == 0 {
|
|
||||||
return errors.New("not where")
|
|
||||||
}
|
|
||||||
|
|
||||||
for colName := range t.wheres {
|
|
||||||
if isBlank(reflect.ValueOf(t.wheres[colName])) {
|
|
||||||
//如果是空值
|
|
||||||
return t.getEmptyError()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
query := NewQuery(t.tableName)
|
|
||||||
for _, where := range t.wheres {
|
|
||||||
if where.emptyCheck {
|
|
||||||
//检查空值
|
|
||||||
if isBlank(reflect.ValueOf(where.value)) {
|
|
||||||
return t.getEmptyError()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
query.Where(where.colName, where.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := query.Take(data)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return t.getEmptyError()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *QueryManager) getEmptyError() error {
|
|
||||||
if t.errorText != "" {
|
|
||||||
return errors.New(t.errorText)
|
|
||||||
} else {
|
|
||||||
return errors.New("不存在")
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user