Compare commits
14 Commits
e7579512c1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a42e055ae | |||
| c2807b54df | |||
| 96f0919c05 | |||
| 36621140f8 | |||
| 39fa373c01 | |||
| defe0b8fff | |||
| aa42046fe9 | |||
| 5f132568cb | |||
| d351a07c85 | |||
| 9f341c7c14 | |||
| 69a389f32c | |||
| 6c124f9f3f | |||
| f80167df85 | |||
| 23b2220903 |
33
app/app.go
33
app/app.go
@@ -6,7 +6,9 @@ import (
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/module"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/grpc_server"
|
||||
"github.com/judwhite/go-svc"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Program struct {
|
||||
@@ -14,21 +16,16 @@ type Program struct {
|
||||
}
|
||||
|
||||
func (p *Program) Init(_ svc.Environment) error {
|
||||
base := &ModuleBase{}
|
||||
if err := base.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
p.moduleList = append(p.moduleList, base)
|
||||
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB))
|
||||
p.moduleList = append(p.moduleList, &ModuleGrpcServer{})
|
||||
p.moduleList = append(p.moduleList, (&module.Prometheus{}).Bind(config.Get().Metric))
|
||||
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameQgdzs))
|
||||
p.moduleList = append(p.moduleList, &module.Log{Cfg: config.Get().Log})
|
||||
p.moduleList = append(p.moduleList, &module.DB{Cfg: config.Get().DB, AppName: config.Get().App.Name})
|
||||
p.moduleList = append(p.moduleList, &module.Snowflake{})
|
||||
p.moduleList = append(p.moduleList, &module.Grpc{Server: grpc_server.NewServer(config.Get().Serve.Grpc)})
|
||||
p.moduleList = append(p.moduleList, &ModuleTimer{})
|
||||
p.moduleList = append(p.moduleList, &module.Prometheus{Cfg: config.Get().Metric})
|
||||
p.moduleList = append(p.moduleList, &module.Tracer{Cfg: config.Get().Metric, ServiceName: common.KeyDiscoverServiceNameQgdzs})
|
||||
p.moduleList = append(p.moduleList, &module.Discover{})
|
||||
|
||||
for i, m := range p.moduleList {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
for _, m := range p.moduleList {
|
||||
if err := m.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -38,8 +35,16 @@ func (p *Program) Init(_ svc.Environment) error {
|
||||
}
|
||||
|
||||
func (p *Program) Start() error {
|
||||
ready := &sync.WaitGroup{}
|
||||
ready.Add(len(p.moduleList))
|
||||
for _, m := range p.moduleList {
|
||||
if err := m.Start(); err != nil {
|
||||
if err := m.Start(ready); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
ready.Wait()
|
||||
for _, m := range p.moduleList {
|
||||
if err := m.AfterStart(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
38
app/base.go
38
app/base.go
@@ -1,38 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/module"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
// ModuleBase 基础模块,或者一些零散的模块
|
||||
type ModuleBase struct {
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Init() error {
|
||||
// 配置
|
||||
if err := config.LoadConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
cfg := config.Get()
|
||||
// 日志
|
||||
log.Init(cfg.Log.Debug, cfg.Log.MaxSize, cfg.Log.MaxBackups, cfg.Log.MaxAge, cfg.Log.Level)
|
||||
// 雪花
|
||||
utils.InitSnowflake(int64(rand.Intn(1000)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleBase) Bind(_ ...any) module.Module {
|
||||
return m
|
||||
}
|
||||
32
app/grpc.go
32
app/grpc.go
@@ -1,32 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/mmorpg/service-common/module"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/service"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/grpc_server"
|
||||
)
|
||||
|
||||
// ModuleGrpcServer Grpc服务模块
|
||||
type ModuleGrpcServer struct {
|
||||
server service.IService
|
||||
}
|
||||
|
||||
func (m *ModuleGrpcServer) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleGrpcServer) Start() error {
|
||||
m.server = grpc_server.NewServer(config.Get().Serve.Grpc.TTL)
|
||||
m.server.Init(config.Get().Serve.Grpc.Address, config.Get().Serve.Grpc.Port)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleGrpcServer) Stop() error {
|
||||
m.server.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleGrpcServer) Bind(_ ...any) module.Module {
|
||||
return m
|
||||
}
|
||||
29
app/timer.go
Normal file
29
app/timer.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/mmorpg/service-common/module"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ModuleTimer 定时器模块
|
||||
type ModuleTimer struct {
|
||||
module.DefaultModule
|
||||
timer *timer.Timer
|
||||
}
|
||||
|
||||
func (m *ModuleTimer) Init() error {
|
||||
m.timer = &timer.Timer{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleTimer) Start(ready *sync.WaitGroup) error {
|
||||
m.timer.Start()
|
||||
ready.Done()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ModuleTimer) Stop() error {
|
||||
m.timer.Stop()
|
||||
return nil
|
||||
}
|
||||
@@ -13,26 +13,28 @@ metric:
|
||||
address: "0.0.0.0"
|
||||
port: 18601
|
||||
jaeger:
|
||||
endpoint: "47.108.184.184:4317"
|
||||
endpoint: "127.0.0.1:4317"
|
||||
|
||||
db:
|
||||
etcd:
|
||||
endpoints: [ "10.0.40.9:2379" ]
|
||||
endpoints: [ "127.0.0.1:2379" ]
|
||||
mysql:
|
||||
qgdzs_db:
|
||||
dsn: "root:gR9pV4tY7zR6qL3e@tcp(47.108.184.184:3306)/qgdzs_db?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
dsn: "root:gR9pV4tY7zR6qL3e@tcp(127.0.0.1:3306)/qgdzs_db?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
maxOpenConn: 50
|
||||
maxIdleConn: 20
|
||||
connMaxLifetimeSec: 600
|
||||
connMaxIdleTimeSec: 180
|
||||
logLevel: "info"
|
||||
logLevel: "warn"
|
||||
redis:
|
||||
addr: "47.108.184.184:6379"
|
||||
addr: "127.0.0.1:6379"
|
||||
password: "lQ7aM8oB6lK0iD5k"
|
||||
db: 0
|
||||
kafka:
|
||||
brokers: [ "127.0.0.1:9092" ]
|
||||
|
||||
serve:
|
||||
grpc:
|
||||
address: "10.0.40.199"
|
||||
address: "127.0.0.1"
|
||||
port: 18600
|
||||
ttl: 20
|
||||
|
||||
@@ -30,6 +30,9 @@ db:
|
||||
addr: "172.18.28.0:6379"
|
||||
password: "lQ7aM8oB6lK0iD5k"
|
||||
db: 0
|
||||
kafka:
|
||||
groupID: "qgdzs"
|
||||
brokers: [ "172.18.28.0:9095" ]
|
||||
|
||||
serve:
|
||||
grpc:
|
||||
|
||||
18
go.mod
18
go.mod
@@ -3,8 +3,9 @@ module git.hlsq.asia/mmorpg/service-qgdzs
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14
|
||||
github.com/judwhite/go-svc v1.2.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
google.golang.org/grpc v1.77.0
|
||||
gorm.io/gen v0.3.27
|
||||
gorm.io/gorm v1.31.1
|
||||
@@ -13,6 +14,7 @@ require (
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/IBM/sarama v1.46.3 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||
github.com/bytedance/gopkg v0.1.3 // indirect
|
||||
@@ -25,6 +27,9 @@ require (
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/eapache/go-resiliency v1.7.0 // indirect
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
|
||||
github.com/eapache/queue v1.1.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.11 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
@@ -41,12 +46,19 @@ require (
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
|
||||
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
||||
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
|
||||
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
|
||||
github.com/jcmturner/gofork v1.7.6 // indirect
|
||||
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
|
||||
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/klauspost/compress v1.18.1 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
@@ -56,6 +68,7 @@ require (
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||
github.com/panjf2000/gnet/v2 v2.9.7 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_golang v1.20.5 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
@@ -63,6 +76,7 @@ require (
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
github.com/quic-go/quic-go v0.57.1 // indirect
|
||||
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 // indirect
|
||||
github.com/redis/go-redis/v9 v9.10.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
|
||||
67
go.sum
67
go.sum
@@ -1,9 +1,11 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852 h1:ehZ54MgGL3CO7KKDPxybFabIXxiQud1TGMcKjrSTcnw=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14 h1:4r3tNWRzGVY3Xx6UiGjJJnwoMoWlVqbyGrljxl5d/nQ=
|
||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
||||
github.com/IBM/sarama v1.46.3/go.mod h1:GTUYiF9DMOZVe3FwyGT+dtSPceGFIgA+sPc5u6CBwko=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
@@ -33,6 +35,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA=
|
||||
github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0=
|
||||
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
@@ -75,13 +85,20 @@ github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei
|
||||
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
|
||||
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
|
||||
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
|
||||
@@ -90,6 +107,18 @@ github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
|
||||
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
|
||||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
||||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
|
||||
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
|
||||
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
|
||||
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
|
||||
github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
|
||||
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
|
||||
github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
|
||||
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
|
||||
github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
|
||||
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
|
||||
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
|
||||
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
@@ -101,8 +130,8 @@ github.com/judwhite/go-svc v1.2.1 h1:a7fsJzYUa33sfDJRF2N/WXhA+LonCEEY8BJb1tuS5tA
|
||||
github.com/judwhite/go-svc v1.2.1/go.mod h1:mo/P2JNX8C07ywpP9YtO2gnBgnUiFTHqtsZekJrUuTk=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
|
||||
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
@@ -133,6 +162,8 @@ github.com/panjf2000/gnet/v2 v2.9.7 h1:6zW7Jl3oAfXwSuh1PxHLndoL2MQRWx0AJR6aaQjxU
|
||||
github.com/panjf2000/gnet/v2 v2.9.7/go.mod h1:WQTxDWYuQ/hz3eccH0FN32IVuvZ19HewEWx0l62fx7E=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
|
||||
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
||||
@@ -147,8 +178,12 @@ github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||
github.com/quic-go/quic-go v0.57.1 h1:25KAAR9QR8KZrCZRThWMKVAwGoiHIrNbT72ULHTuI10=
|
||||
github.com/quic-go/quic-go v0.57.1/go.mod h1:ly4QBAjHA2VhdnxhojRsCUOeJwKYg+taDlos92xb1+s=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 h1:bsUq1dX0N8AOIL7EB/X911+m4EHsnWEHeJ0c+3TTBrg=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs=
|
||||
github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||
@@ -168,9 +203,11 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
@@ -183,6 +220,7 @@ github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY
|
||||
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.etcd.io/etcd/api/v3 v3.6.1 h1:yJ9WlDih9HT457QPuHt/TH/XtsdN2tubyxyQHSHPsEo=
|
||||
go.etcd.io/etcd/api/v3 v3.6.1/go.mod h1:lnfuqoGsXMlZdTJlact3IB56o3bWp1DIlXPIGKRArto=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.6.1 h1:CxDVv8ggphmamrXM4Of8aCC8QHzDM4tGcVr9p2BSoGk=
|
||||
@@ -224,32 +262,51 @@ golang.org/x/arch v0.23.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
|
||||
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
|
||||
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
||||
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
|
||||
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
|
||||
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
|
||||
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
||||
@@ -258,6 +315,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
|
||||
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -279,6 +337,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -16,7 +16,7 @@ const TableNameCategory = "categories"
|
||||
// Category mapped from table <categories>
|
||||
type Category struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
Category string `gorm:"column:category;not null;comment:分类" json:"category"` // 分类
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||
@@ -30,8 +30,8 @@ func (*Category) TableName() string {
|
||||
|
||||
// Auto sn
|
||||
func (m *Category) BeforeCreate(_ *gorm.DB) error {
|
||||
if m.Sn == "" {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
||||
if m.Sn == 0 {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
38
internal/dao/model/point_card.gen.go
Normal file
38
internal/dao/model/point_card.gen.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNamePointCard = "point_card"
|
||||
|
||||
// PointCard mapped from table <point_card>
|
||||
type PointCard struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
||||
Point int64 `gorm:"column:point;not null;comment:积分" json:"point"` // 积分
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
|
||||
}
|
||||
|
||||
// TableName PointCard's table name
|
||||
func (*PointCard) TableName() string {
|
||||
return TableNamePointCard
|
||||
}
|
||||
|
||||
// Auto sn
|
||||
func (m *PointCard) BeforeCreate(_ *gorm.DB) error {
|
||||
if m.Sn == 0 {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
46
internal/dao/model/point_records.gen.go
Normal file
46
internal/dao/model/point_records.gen.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNamePointRecord = "point_records"
|
||||
|
||||
// PointRecord mapped from table <point_records>
|
||||
type PointRecord struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
||||
/*
|
||||
来源:
|
||||
0. 未知
|
||||
1. 随机答题
|
||||
2. 类目答题
|
||||
3. 限时答题
|
||||
*/
|
||||
Source int32 `gorm:"column:source;not null;comment:来源:\n0. 未知\n1. 随机答题\n2. 类目答题\n3. 限时答题" json:"source"`
|
||||
Point int64 `gorm:"column:point;not null;comment:积分" json:"point"` // 积分
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
|
||||
}
|
||||
|
||||
// TableName PointRecord's table name
|
||||
func (*PointRecord) TableName() string {
|
||||
return TableNamePointRecord
|
||||
}
|
||||
|
||||
// Auto sn
|
||||
func (m *PointRecord) BeforeCreate(_ *gorm.DB) error {
|
||||
if m.Sn == 0 {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -16,13 +16,13 @@ const TableNameQuestion = "questions"
|
||||
// Question mapped from table <questions>
|
||||
type Question struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
Question string `gorm:"column:question;not null;comment:题干" json:"question"` // 题干
|
||||
Options string `gorm:"column:options;not null;comment:选项" json:"options"` // 选项
|
||||
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
|
||||
Explanation string `gorm:"column:explanation;not null;comment:解析" json:"explanation"` // 解析
|
||||
Difficulty int32 `gorm:"column:difficulty;not null;comment:难度分 0 - 100" json:"difficulty"` // 难度分 0 - 100
|
||||
CategorySn string `gorm:"column:category_sn;not null;comment:分类-唯一编号" json:"category_sn"` // 分类-唯一编号
|
||||
CategorySn int64 `gorm:"column:category_sn;not null;comment:分类-唯一编号" json:"category_sn"` // 分类-唯一编号
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
|
||||
@@ -35,8 +35,8 @@ func (*Question) TableName() string {
|
||||
|
||||
// Auto sn
|
||||
func (m *Question) BeforeCreate(_ *gorm.DB) error {
|
||||
if m.Sn == "" {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
||||
if m.Sn == 0 {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ const TableNameRecord = "records"
|
||||
// Record mapped from table <records>
|
||||
type Record struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
||||
QuestionSn string `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号
|
||||
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
||||
QuestionSn int64 `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号
|
||||
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
|
||||
IsCorrect int32 `gorm:"column:is_correct;not null;comment:是否正确 0 否 1 是" json:"is_correct"` // 是否正确 0 否 1 是
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||
@@ -33,8 +33,8 @@ func (*Record) TableName() string {
|
||||
|
||||
// Auto sn
|
||||
func (m *Record) BeforeCreate(_ *gorm.DB) error {
|
||||
if m.Sn == "" {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
||||
if m.Sn == 0 {
|
||||
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func newCategory(db *gorm.DB, opts ...gen.DOOption) category {
|
||||
tableName := _category.categoryDo.TableName()
|
||||
_category.ALL = field.NewAsterisk(tableName)
|
||||
_category.ID = field.NewUint64(tableName, "id")
|
||||
_category.Sn = field.NewString(tableName, "sn")
|
||||
_category.Sn = field.NewInt64(tableName, "sn")
|
||||
_category.Category = field.NewString(tableName, "category")
|
||||
_category.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_category.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
@@ -44,7 +44,7 @@ type category struct {
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Sn field.String // 业务唯一编号
|
||||
Sn field.Int64 // 业务唯一编号
|
||||
Category field.String // 分类
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
@@ -66,7 +66,7 @@ func (c category) As(alias string) *category {
|
||||
func (c *category) updateTableName(table string) *category {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewUint64(table, "id")
|
||||
c.Sn = field.NewString(table, "sn")
|
||||
c.Sn = field.NewInt64(table, "sn")
|
||||
c.Category = field.NewString(table, "category")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
@@ -17,29 +17,35 @@ import (
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Category: newCategory(db, opts...),
|
||||
Question: newQuestion(db, opts...),
|
||||
Record: newRecord(db, opts...),
|
||||
db: db,
|
||||
Category: newCategory(db, opts...),
|
||||
PointCard: newPointCard(db, opts...),
|
||||
PointRecord: newPointRecord(db, opts...),
|
||||
Question: newQuestion(db, opts...),
|
||||
Record: newRecord(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
Category category
|
||||
Question question
|
||||
Record record
|
||||
Category category
|
||||
PointCard pointCard
|
||||
PointRecord pointRecord
|
||||
Question question
|
||||
Record record
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Category: q.Category.clone(db),
|
||||
Question: q.Question.clone(db),
|
||||
Record: q.Record.clone(db),
|
||||
db: db,
|
||||
Category: q.Category.clone(db),
|
||||
PointCard: q.PointCard.clone(db),
|
||||
PointRecord: q.PointRecord.clone(db),
|
||||
Question: q.Question.clone(db),
|
||||
Record: q.Record.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,24 +59,30 @@ func (q *Query) WriteDB() *Query {
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Category: q.Category.replaceDB(db),
|
||||
Question: q.Question.replaceDB(db),
|
||||
Record: q.Record.replaceDB(db),
|
||||
db: db,
|
||||
Category: q.Category.replaceDB(db),
|
||||
PointCard: q.PointCard.replaceDB(db),
|
||||
PointRecord: q.PointRecord.replaceDB(db),
|
||||
Question: q.Question.replaceDB(db),
|
||||
Record: q.Record.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
Category *categoryDo
|
||||
Question *questionDo
|
||||
Record *recordDo
|
||||
Category *categoryDo
|
||||
PointCard *pointCardDo
|
||||
PointRecord *pointRecordDo
|
||||
Question *questionDo
|
||||
Record *recordDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
Category: q.Category.WithContext(ctx),
|
||||
Question: q.Question.WithContext(ctx),
|
||||
Record: q.Record.WithContext(ctx),
|
||||
Category: q.Category.WithContext(ctx),
|
||||
PointCard: q.PointCard.WithContext(ctx),
|
||||
PointRecord: q.PointRecord.WithContext(ctx),
|
||||
Question: q.Question.WithContext(ctx),
|
||||
Record: q.Record.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
353
internal/dao/query/point_card.gen.go
Normal file
353
internal/dao/query/point_card.gen.go
Normal file
@@ -0,0 +1,353 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
)
|
||||
|
||||
func newPointCard(db *gorm.DB, opts ...gen.DOOption) pointCard {
|
||||
_pointCard := pointCard{}
|
||||
|
||||
_pointCard.pointCardDo.UseDB(db, opts...)
|
||||
_pointCard.pointCardDo.UseModel(&model.PointCard{})
|
||||
|
||||
tableName := _pointCard.pointCardDo.TableName()
|
||||
_pointCard.ALL = field.NewAsterisk(tableName)
|
||||
_pointCard.ID = field.NewUint64(tableName, "id")
|
||||
_pointCard.Sn = field.NewInt64(tableName, "sn")
|
||||
_pointCard.UserSn = field.NewInt64(tableName, "user_sn")
|
||||
_pointCard.Point = field.NewInt64(tableName, "point")
|
||||
_pointCard.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_pointCard.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_pointCard.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_pointCard.fillFieldMap()
|
||||
|
||||
return _pointCard
|
||||
}
|
||||
|
||||
type pointCard struct {
|
||||
pointCardDo pointCardDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Sn field.Int64 // 业务唯一编号
|
||||
UserSn field.Int64 // 用户-唯一编号
|
||||
Point field.Int64 // 积分
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p pointCard) Table(newTableName string) *pointCard {
|
||||
p.pointCardDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p pointCard) As(alias string) *pointCard {
|
||||
p.pointCardDo.DO = *(p.pointCardDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *pointCard) updateTableName(table string) *pointCard {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewUint64(table, "id")
|
||||
p.Sn = field.NewInt64(table, "sn")
|
||||
p.UserSn = field.NewInt64(table, "user_sn")
|
||||
p.Point = field.NewInt64(table, "point")
|
||||
p.CreatedAt = field.NewTime(table, "created_at")
|
||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
p.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *pointCard) WithContext(ctx context.Context) *pointCardDo {
|
||||
return p.pointCardDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (p pointCard) TableName() string { return p.pointCardDo.TableName() }
|
||||
|
||||
func (p pointCard) Alias() string { return p.pointCardDo.Alias() }
|
||||
|
||||
func (p pointCard) Columns(cols ...field.Expr) gen.Columns { return p.pointCardDo.Columns(cols...) }
|
||||
|
||||
func (p *pointCard) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *pointCard) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 7)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["sn"] = p.Sn
|
||||
p.fieldMap["user_sn"] = p.UserSn
|
||||
p.fieldMap["point"] = p.Point
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["deleted_at"] = p.DeletedAt
|
||||
}
|
||||
|
||||
func (p pointCard) clone(db *gorm.DB) pointCard {
|
||||
p.pointCardDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p pointCard) replaceDB(db *gorm.DB) pointCard {
|
||||
p.pointCardDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type pointCardDo struct{ gen.DO }
|
||||
|
||||
func (p pointCardDo) Debug() *pointCardDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p pointCardDo) WithContext(ctx context.Context) *pointCardDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p pointCardDo) ReadDB() *pointCardDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p pointCardDo) WriteDB() *pointCardDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p pointCardDo) Session(config *gorm.Session) *pointCardDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Clauses(conds ...clause.Expression) *pointCardDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Returning(value interface{}, columns ...string) *pointCardDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Not(conds ...gen.Condition) *pointCardDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Or(conds ...gen.Condition) *pointCardDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Select(conds ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Where(conds ...gen.Condition) *pointCardDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Order(conds ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Distinct(cols ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Omit(cols ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Join(table schema.Tabler, on ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) LeftJoin(table schema.Tabler, on ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) RightJoin(table schema.Tabler, on ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Group(cols ...field.Expr) *pointCardDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Having(conds ...gen.Condition) *pointCardDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Limit(limit int) *pointCardDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Offset(offset int) *pointCardDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *pointCardDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Unscoped() *pointCardDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p pointCardDo) Create(values ...*model.PointCard) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p pointCardDo) CreateInBatches(values []*model.PointCard, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p pointCardDo) Save(values ...*model.PointCard) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p pointCardDo) First() (*model.PointCard, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointCard), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointCardDo) Take() (*model.PointCard, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointCard), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointCardDo) Last() (*model.PointCard, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointCard), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointCardDo) Find() ([]*model.PointCard, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.PointCard), err
|
||||
}
|
||||
|
||||
func (p pointCardDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PointCard, err error) {
|
||||
buf := make([]*model.PointCard, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p pointCardDo) FindInBatches(result *[]*model.PointCard, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p pointCardDo) Attrs(attrs ...field.AssignExpr) *pointCardDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Assign(attrs ...field.AssignExpr) *pointCardDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p pointCardDo) Joins(fields ...field.RelationField) *pointCardDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pointCardDo) Preload(fields ...field.RelationField) *pointCardDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pointCardDo) FirstOrInit() (*model.PointCard, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointCard), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointCardDo) FirstOrCreate() (*model.PointCard, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointCard), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointCardDo) FindByPage(offset int, limit int) (result []*model.PointCard, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p pointCardDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p pointCardDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p pointCardDo) Delete(models ...*model.PointCard) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *pointCardDo) withDO(do gen.Dao) *pointCardDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
364
internal/dao/query/point_records.gen.go
Normal file
364
internal/dao/query/point_records.gen.go
Normal file
@@ -0,0 +1,364 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
)
|
||||
|
||||
func newPointRecord(db *gorm.DB, opts ...gen.DOOption) pointRecord {
|
||||
_pointRecord := pointRecord{}
|
||||
|
||||
_pointRecord.pointRecordDo.UseDB(db, opts...)
|
||||
_pointRecord.pointRecordDo.UseModel(&model.PointRecord{})
|
||||
|
||||
tableName := _pointRecord.pointRecordDo.TableName()
|
||||
_pointRecord.ALL = field.NewAsterisk(tableName)
|
||||
_pointRecord.ID = field.NewUint64(tableName, "id")
|
||||
_pointRecord.Sn = field.NewInt64(tableName, "sn")
|
||||
_pointRecord.UserSn = field.NewInt64(tableName, "user_sn")
|
||||
_pointRecord.Source = field.NewInt32(tableName, "source")
|
||||
_pointRecord.Point = field.NewInt64(tableName, "point")
|
||||
_pointRecord.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_pointRecord.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_pointRecord.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_pointRecord.fillFieldMap()
|
||||
|
||||
return _pointRecord
|
||||
}
|
||||
|
||||
type pointRecord struct {
|
||||
pointRecordDo pointRecordDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Sn field.Int64 // 业务唯一编号
|
||||
UserSn field.Int64 // 用户-唯一编号
|
||||
/*
|
||||
来源:
|
||||
0. 未知
|
||||
1. 随机答题
|
||||
2. 类目答题
|
||||
3. 限时答题
|
||||
*/
|
||||
Source field.Int32
|
||||
Point field.Int64 // 积分
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p pointRecord) Table(newTableName string) *pointRecord {
|
||||
p.pointRecordDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p pointRecord) As(alias string) *pointRecord {
|
||||
p.pointRecordDo.DO = *(p.pointRecordDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *pointRecord) updateTableName(table string) *pointRecord {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewUint64(table, "id")
|
||||
p.Sn = field.NewInt64(table, "sn")
|
||||
p.UserSn = field.NewInt64(table, "user_sn")
|
||||
p.Source = field.NewInt32(table, "source")
|
||||
p.Point = field.NewInt64(table, "point")
|
||||
p.CreatedAt = field.NewTime(table, "created_at")
|
||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
p.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *pointRecord) WithContext(ctx context.Context) *pointRecordDo {
|
||||
return p.pointRecordDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (p pointRecord) TableName() string { return p.pointRecordDo.TableName() }
|
||||
|
||||
func (p pointRecord) Alias() string { return p.pointRecordDo.Alias() }
|
||||
|
||||
func (p pointRecord) Columns(cols ...field.Expr) gen.Columns { return p.pointRecordDo.Columns(cols...) }
|
||||
|
||||
func (p *pointRecord) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *pointRecord) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 8)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["sn"] = p.Sn
|
||||
p.fieldMap["user_sn"] = p.UserSn
|
||||
p.fieldMap["source"] = p.Source
|
||||
p.fieldMap["point"] = p.Point
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["deleted_at"] = p.DeletedAt
|
||||
}
|
||||
|
||||
func (p pointRecord) clone(db *gorm.DB) pointRecord {
|
||||
p.pointRecordDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p pointRecord) replaceDB(db *gorm.DB) pointRecord {
|
||||
p.pointRecordDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type pointRecordDo struct{ gen.DO }
|
||||
|
||||
func (p pointRecordDo) Debug() *pointRecordDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p pointRecordDo) WithContext(ctx context.Context) *pointRecordDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) ReadDB() *pointRecordDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p pointRecordDo) WriteDB() *pointRecordDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Session(config *gorm.Session) *pointRecordDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Clauses(conds ...clause.Expression) *pointRecordDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Returning(value interface{}, columns ...string) *pointRecordDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Not(conds ...gen.Condition) *pointRecordDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Or(conds ...gen.Condition) *pointRecordDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Select(conds ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Where(conds ...gen.Condition) *pointRecordDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Order(conds ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Distinct(cols ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Omit(cols ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Join(table schema.Tabler, on ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) LeftJoin(table schema.Tabler, on ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) RightJoin(table schema.Tabler, on ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Group(cols ...field.Expr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Having(conds ...gen.Condition) *pointRecordDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Limit(limit int) *pointRecordDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Offset(offset int) *pointRecordDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *pointRecordDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Unscoped() *pointRecordDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Create(values ...*model.PointRecord) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p pointRecordDo) CreateInBatches(values []*model.PointRecord, batchSize int) error {
|
||||
return p.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (p pointRecordDo) Save(values ...*model.PointRecord) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p pointRecordDo) First() (*model.PointRecord, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointRecord), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Take() (*model.PointRecord, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointRecord), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Last() (*model.PointRecord, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointRecord), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Find() ([]*model.PointRecord, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.PointRecord), err
|
||||
}
|
||||
|
||||
func (p pointRecordDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PointRecord, err error) {
|
||||
buf := make([]*model.PointRecord, 0, batchSize)
|
||||
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (p pointRecordDo) FindInBatches(result *[]*model.PointRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Attrs(attrs ...field.AssignExpr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Assign(attrs ...field.AssignExpr) *pointRecordDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Joins(fields ...field.RelationField) *pointRecordDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Preload(fields ...field.RelationField) *pointRecordDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p pointRecordDo) FirstOrInit() (*model.PointRecord, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointRecord), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointRecordDo) FirstOrCreate() (*model.PointRecord, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.PointRecord), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p pointRecordDo) FindByPage(offset int, limit int) (result []*model.PointRecord, count int64, err error) {
|
||||
result, err = p.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p pointRecordDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p pointRecordDo) Delete(models ...*model.PointRecord) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *pointRecordDo) withDO(do gen.Dao) *pointRecordDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
@@ -28,13 +28,13 @@ func newQuestion(db *gorm.DB, opts ...gen.DOOption) question {
|
||||
tableName := _question.questionDo.TableName()
|
||||
_question.ALL = field.NewAsterisk(tableName)
|
||||
_question.ID = field.NewUint64(tableName, "id")
|
||||
_question.Sn = field.NewString(tableName, "sn")
|
||||
_question.Sn = field.NewInt64(tableName, "sn")
|
||||
_question.Question = field.NewString(tableName, "question")
|
||||
_question.Options = field.NewString(tableName, "options")
|
||||
_question.Answer = field.NewString(tableName, "answer")
|
||||
_question.Explanation = field.NewString(tableName, "explanation")
|
||||
_question.Difficulty = field.NewInt32(tableName, "difficulty")
|
||||
_question.CategorySn = field.NewString(tableName, "category_sn")
|
||||
_question.CategorySn = field.NewInt64(tableName, "category_sn")
|
||||
_question.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_question.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_question.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
@@ -49,13 +49,13 @@ type question struct {
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Sn field.String // 业务唯一编号
|
||||
Sn field.Int64 // 业务唯一编号
|
||||
Question field.String // 题干
|
||||
Options field.String // 选项
|
||||
Answer field.String // 答案
|
||||
Explanation field.String // 解析
|
||||
Difficulty field.Int32 // 难度分 0 - 100
|
||||
CategorySn field.String // 分类-唯一编号
|
||||
CategorySn field.Int64 // 分类-唯一编号
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
@@ -76,13 +76,13 @@ func (q question) As(alias string) *question {
|
||||
func (q *question) updateTableName(table string) *question {
|
||||
q.ALL = field.NewAsterisk(table)
|
||||
q.ID = field.NewUint64(table, "id")
|
||||
q.Sn = field.NewString(table, "sn")
|
||||
q.Sn = field.NewInt64(table, "sn")
|
||||
q.Question = field.NewString(table, "question")
|
||||
q.Options = field.NewString(table, "options")
|
||||
q.Answer = field.NewString(table, "answer")
|
||||
q.Explanation = field.NewString(table, "explanation")
|
||||
q.Difficulty = field.NewInt32(table, "difficulty")
|
||||
q.CategorySn = field.NewString(table, "category_sn")
|
||||
q.CategorySn = field.NewInt64(table, "category_sn")
|
||||
q.CreatedAt = field.NewTime(table, "created_at")
|
||||
q.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
q.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
@@ -28,9 +28,9 @@ func newRecord(db *gorm.DB, opts ...gen.DOOption) record {
|
||||
tableName := _record.recordDo.TableName()
|
||||
_record.ALL = field.NewAsterisk(tableName)
|
||||
_record.ID = field.NewUint64(tableName, "id")
|
||||
_record.Sn = field.NewString(tableName, "sn")
|
||||
_record.UserSn = field.NewString(tableName, "user_sn")
|
||||
_record.QuestionSn = field.NewString(tableName, "question_sn")
|
||||
_record.Sn = field.NewInt64(tableName, "sn")
|
||||
_record.UserSn = field.NewInt64(tableName, "user_sn")
|
||||
_record.QuestionSn = field.NewInt64(tableName, "question_sn")
|
||||
_record.Answer = field.NewString(tableName, "answer")
|
||||
_record.IsCorrect = field.NewInt32(tableName, "is_correct")
|
||||
_record.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
@@ -47,9 +47,9 @@ type record struct {
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
Sn field.String // 业务唯一编号
|
||||
UserSn field.String // 用户-唯一编号
|
||||
QuestionSn field.String // 题目-唯一编号
|
||||
Sn field.Int64 // 业务唯一编号
|
||||
UserSn field.Int64 // 用户-唯一编号
|
||||
QuestionSn field.Int64 // 题目-唯一编号
|
||||
Answer field.String // 答案
|
||||
IsCorrect field.Int32 // 是否正确 0 否 1 是
|
||||
CreatedAt field.Time
|
||||
@@ -72,9 +72,9 @@ func (r record) As(alias string) *record {
|
||||
func (r *record) updateTableName(table string) *record {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewUint64(table, "id")
|
||||
r.Sn = field.NewString(table, "sn")
|
||||
r.UserSn = field.NewString(table, "user_sn")
|
||||
r.QuestionSn = field.NewString(table, "question_sn")
|
||||
r.Sn = field.NewInt64(table, "sn")
|
||||
r.UserSn = field.NewInt64(table, "user_sn")
|
||||
r.QuestionSn = field.NewInt64(table, "question_sn")
|
||||
r.Answer = field.NewString(table, "answer")
|
||||
r.IsCorrect = field.NewInt32(table, "is_correct")
|
||||
r.CreatedAt = field.NewTime(table, "created_at")
|
||||
|
||||
@@ -2,7 +2,6 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
||||
@@ -14,10 +13,10 @@ type CategoryDao struct {
|
||||
cache *redis.CacheClient
|
||||
}
|
||||
|
||||
func NewCategoryDao(ctx context.Context, cache ...*redis.CacheClient) *CategoryDao {
|
||||
func NewCategoryDao(ctx context.Context, query *query.Query, cache ...*redis.CacheClient) *CategoryDao {
|
||||
dao := &CategoryDao{
|
||||
ctx: ctx,
|
||||
query: query.Use(mysql.GetDB(dbName)),
|
||||
query: query,
|
||||
}
|
||||
if len(cache) > 0 {
|
||||
dao.cache = cache[0]
|
||||
@@ -41,7 +40,7 @@ func (d *CategoryDao) FindAll() ([]*model.Category, error) {
|
||||
return find, nil
|
||||
}
|
||||
|
||||
func (d *CategoryDao) FindNameBySn(sn string) (string, error) {
|
||||
func (d *CategoryDao) FindNameBySn(sn int64) (string, error) {
|
||||
first, err := d.query.Category.WithContext(d.ctx).
|
||||
Select(d.query.Category.Category).
|
||||
Where(d.query.Category.Sn.Eq(sn)).
|
||||
@@ -52,13 +51,13 @@ func (d *CategoryDao) FindNameBySn(sn string) (string, error) {
|
||||
return first.Category, nil
|
||||
}
|
||||
|
||||
func (d *CategoryDao) FindSnByName(category string) (string, error) {
|
||||
func (d *CategoryDao) FindSnByName(category string) (int64, error) {
|
||||
first, err := d.query.Category.WithContext(d.ctx).
|
||||
Select(d.query.Category.Sn).
|
||||
Where(d.query.Category.Category.Eq(category)).
|
||||
First()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return 0, err
|
||||
}
|
||||
return first.Sn, nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
||||
)
|
||||
|
||||
var dbName mysql.DBName = "qgdzs_db"
|
||||
@@ -11,6 +12,10 @@ var (
|
||||
cacheBySn = "c:%v:s:%v"
|
||||
)
|
||||
|
||||
func keyCacheBySn(sn string, tableName string) string {
|
||||
func Query() *query.Query {
|
||||
return query.Use(mysql.GetDB(dbName))
|
||||
}
|
||||
|
||||
func keyCacheBySn(sn int64, tableName string) string {
|
||||
return fmt.Sprintf(cacheBySn, tableName, sn)
|
||||
}
|
||||
|
||||
53
internal/dao/repository/point_card.go
Normal file
53
internal/dao/repository/point_card.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
||||
)
|
||||
|
||||
type PointCardDao struct {
|
||||
ctx context.Context
|
||||
query *query.Query
|
||||
cache *redis.CacheClient
|
||||
}
|
||||
|
||||
func NewPointCardDao(ctx context.Context, query *query.Query, cache ...*redis.CacheClient) *PointCardDao {
|
||||
dao := &PointCardDao{
|
||||
ctx: ctx,
|
||||
query: query,
|
||||
}
|
||||
if len(cache) > 0 {
|
||||
dao.cache = cache[0]
|
||||
}
|
||||
return dao
|
||||
}
|
||||
|
||||
func (d *PointCardDao) Create(pointCard *model.PointCard) (*model.PointCard, error) {
|
||||
err := d.query.PointCard.WithContext(d.ctx).
|
||||
Create(pointCard)
|
||||
return pointCard, err
|
||||
}
|
||||
|
||||
func (d *PointCardDao) IncrPointCard(usn int64, point int64) error {
|
||||
info, err := d.query.PointCard.WithContext(d.ctx).
|
||||
Where(d.query.PointCard.UserSn.Eq(usn)).
|
||||
UpdateSimple(d.query.PointCard.Point.Add(point))
|
||||
if err != nil {
|
||||
return utils.ErrorsWrap(err)
|
||||
}
|
||||
if info.RowsAffected == 0 {
|
||||
return utils.ErrorsWrap(errors.New("user not found"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *PointCardDao) FindPointByUserSn(usn int64) (*model.PointCard, error) {
|
||||
return d.query.PointCard.WithContext(d.ctx).
|
||||
Select(d.query.PointCard.Point).
|
||||
Where(d.query.PointCard.UserSn.Eq(usn)).
|
||||
First()
|
||||
}
|
||||
75
internal/dao/repository/point_records.go
Normal file
75
internal/dao/repository/point_records.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type PointRecordsDao struct {
|
||||
ctx context.Context
|
||||
query *query.Query
|
||||
cache *redis.CacheClient
|
||||
}
|
||||
|
||||
func NewPointRecordsDao(ctx context.Context, query *query.Query, cache ...*redis.CacheClient) *PointRecordsDao {
|
||||
dao := &PointRecordsDao{
|
||||
ctx: ctx,
|
||||
query: query,
|
||||
}
|
||||
if len(cache) > 0 {
|
||||
dao.cache = cache[0]
|
||||
}
|
||||
return dao
|
||||
}
|
||||
|
||||
func (d *PointRecordsDao) CreateAndIncrPointCard(pointRecord *model.PointRecord) error {
|
||||
return d.query.Transaction(func(tx *query.Query) error {
|
||||
if err := tx.PointRecord.WithContext(d.ctx).
|
||||
Create(pointRecord); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pcd := NewPointCardDao(d.ctx, tx)
|
||||
if _, err := pcd.FindPointByUserSn(pointRecord.UserSn); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
_, err = pcd.Create(&model.PointCard{
|
||||
UserSn: pointRecord.UserSn,
|
||||
Point: pointRecord.Point,
|
||||
})
|
||||
if err != nil {
|
||||
return utils.ErrorsWrap(err)
|
||||
}
|
||||
} else {
|
||||
return utils.ErrorsWrap(err)
|
||||
}
|
||||
} else {
|
||||
if err = pcd.IncrPointCard(pointRecord.UserSn, pointRecord.Point); err != nil {
|
||||
return utils.ErrorsWrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (d *PointRecordsDao) FindByUSN(usn int64, page, pageSize int) ([]*model.PointRecord, int64, error) {
|
||||
result := make([]*model.PointRecord, 0)
|
||||
count, err := d.query.PointRecord.WithContext(d.ctx).
|
||||
Select(
|
||||
d.query.PointRecord.Source,
|
||||
d.query.PointRecord.Point,
|
||||
d.query.PointRecord.CreatedAt,
|
||||
).
|
||||
Where(d.query.PointRecord.UserSn.Eq(usn)).
|
||||
Order(d.query.PointRecord.CreatedAt.Desc()).
|
||||
ScanByPage(&result, (page-1)*pageSize, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return result, count, nil
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
@@ -17,10 +16,10 @@ type QuestionDao struct {
|
||||
cache *redis.CacheClient
|
||||
}
|
||||
|
||||
func NewQuestionDao(ctx context.Context, cache ...*redis.CacheClient) *QuestionDao {
|
||||
func NewQuestionDao(ctx context.Context, query *query.Query, cache ...*redis.CacheClient) *QuestionDao {
|
||||
dao := &QuestionDao{
|
||||
ctx: ctx,
|
||||
query: query.Use(mysql.GetDB(dbName)),
|
||||
query: query,
|
||||
}
|
||||
if len(cache) > 0 {
|
||||
dao.cache = cache[0]
|
||||
@@ -34,9 +33,9 @@ func (d *QuestionDao) Create(question *model.Question) (*model.Question, error)
|
||||
return question, err
|
||||
}
|
||||
|
||||
func (d *QuestionDao) FindByRandom(categorySn string) (*model.Question, error) {
|
||||
func (d *QuestionDao) FindByRandom(categorySn int64) (*model.Question, error) {
|
||||
q := d.query.Question.WithContext(d.ctx)
|
||||
if categorySn != "" {
|
||||
if categorySn != 0 {
|
||||
q = q.Where(d.query.Question.CategorySn.Eq(categorySn))
|
||||
}
|
||||
|
||||
@@ -55,7 +54,7 @@ func (d *QuestionDao) FindByRandom(categorySn string) (*model.Question, error) {
|
||||
return first, nil
|
||||
}
|
||||
|
||||
func (d *QuestionDao) FindBySn(sn string) (*model.Question, error) {
|
||||
func (d *QuestionDao) FindBySn(sn int64) (*model.Question, error) {
|
||||
if d.cache != nil {
|
||||
var question model.Question
|
||||
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, question.TableName()), &question); ok {
|
||||
@@ -73,23 +72,3 @@ func (d *QuestionDao) FindBySn(sn string) (*model.Question, error) {
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
|
||||
func (d *QuestionDao) FindByCategory(categorySn string) (*model.Question, error) {
|
||||
count, err := d.query.Question.WithContext(d.ctx).
|
||||
Where(d.query.Question.CategorySn.Eq(categorySn)).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count == 0 {
|
||||
return nil, gorm.ErrRecordNotFound
|
||||
}
|
||||
first, err := d.query.Question.WithContext(d.ctx).
|
||||
Where(d.query.Question.CategorySn.Eq(categorySn)).
|
||||
Offset(utils.RandInt(0, int(count-1))).
|
||||
First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
||||
@@ -15,10 +14,10 @@ type RecordDao struct {
|
||||
cache *redis.CacheClient
|
||||
}
|
||||
|
||||
func NewRecordDao(ctx context.Context, cache ...*redis.CacheClient) *RecordDao {
|
||||
func NewRecordDao(ctx context.Context, query *query.Query, cache ...*redis.CacheClient) *RecordDao {
|
||||
dao := &RecordDao{
|
||||
ctx: ctx,
|
||||
query: query.Use(mysql.GetDB(dbName)),
|
||||
query: query,
|
||||
}
|
||||
if len(cache) > 0 {
|
||||
dao.cache = cache[0]
|
||||
@@ -33,7 +32,7 @@ func (d *RecordDao) Create(record *model.Record) (*model.Record, error) {
|
||||
}
|
||||
|
||||
type RecordItem struct {
|
||||
QuestionSn string `gorm:"column:question_sn"`
|
||||
QuestionSn int64 `gorm:"column:question_sn"`
|
||||
Question string `gorm:"column:question"`
|
||||
Difficulty int32 `gorm:"column:difficulty"`
|
||||
Category string `gorm:"column:category"`
|
||||
@@ -43,7 +42,7 @@ type RecordItem struct {
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
}
|
||||
|
||||
func (d *RecordDao) FindByUSN(usn string, page, pageSize int) ([]*RecordItem, int64, error) {
|
||||
func (d *RecordDao) FindByUSN(usn int64, page, pageSize int) ([]*RecordItem, int64, error) {
|
||||
result := make([]*RecordItem, 0)
|
||||
count, err := d.query.Record.WithContext(d.ctx).
|
||||
Select(
|
||||
|
||||
89
internal/grpc_server/server_category.go
Normal file
89
internal/grpc_server/server_category.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package grpc_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
||||
)
|
||||
|
||||
// 玩法 - 类目答题
|
||||
|
||||
// GetAllCategory 获取所有类目
|
||||
func (s *Server) GetAllCategory(ctx context.Context, req *grpc_pb.GetAllCategoryReq) (*grpc_pb.GetAllCategoryResp, error) {
|
||||
categoryList, err := repository.NewCategoryDao(ctx, s.query).FindAll()
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
categories := make([]*grpc_pb.GetAllCategoryItem, 0)
|
||||
for _, category := range categoryList {
|
||||
categories = append(categories, &grpc_pb.GetAllCategoryItem{
|
||||
Sn: category.Sn,
|
||||
Category: category.Category,
|
||||
})
|
||||
}
|
||||
return &grpc_pb.GetAllCategoryResp{
|
||||
Categories: categories,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CategoryGetQuestion 获取题目
|
||||
func (s *Server) CategoryGetQuestion(ctx context.Context, req *grpc_pb.CategoryGetQuestionReq) (*grpc_pb.CategoryGetQuestionResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(req.CategorySn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||
return &grpc_pb.CategoryGetQuestionResp{
|
||||
Sn: question.Sn,
|
||||
Question: question.Question,
|
||||
Options: options,
|
||||
Category: category,
|
||||
Difficulty: question.Difficulty,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CategoryAnswerQuestion 回答题目
|
||||
func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.CategoryAnswerQuestionReq) (*grpc_pb.CategoryAnswerQuestionResp, error) {
|
||||
utils.ShouldBindUsn(ctx, &req.USN)
|
||||
|
||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
// 保存答题记录
|
||||
if req.USN != 0 {
|
||||
kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{
|
||||
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||
USN: req.USN,
|
||||
QuestionSn: question.Sn,
|
||||
QuestionAnswer: question.Answer,
|
||||
Answer: req.Answer,
|
||||
})
|
||||
|
||||
// 类目答题正确给5分,错误不得分
|
||||
if req.Answer == question.Answer {
|
||||
kafka.NewProducer().Produce(ctx, &timer.TopicAddPoint{
|
||||
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||
Source: timer.AddPointSourceCategory,
|
||||
USN: req.USN,
|
||||
Point: 5,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &grpc_pb.CategoryAnswerQuestionResp{
|
||||
Answer: question.Answer,
|
||||
Explanation: question.Explanation,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,23 +1,27 @@
|
||||
package grpc_server
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/mmorpg/service-common/config"
|
||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/service"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
grpc_pb.UnimplementedQgdzsServer
|
||||
service.Base
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewServer(ttl int64) *Server {
|
||||
func NewServer(cfg *config.GrpcConfig) *Server {
|
||||
s := &Server{
|
||||
Base: service.Base{
|
||||
Target: common.KeyDiscoverQgdzs,
|
||||
ServiceName: common.KeyDiscoverServiceNameQgdzs,
|
||||
EtcdTTL: ttl,
|
||||
Cfg: cfg,
|
||||
},
|
||||
}
|
||||
s.Base.OnCustomGrpcServerOption = s.OnCustomGrpcServerOption
|
||||
@@ -32,6 +36,7 @@ func (s *Server) OnCustomGrpcServerOption() []grpc.ServerOption {
|
||||
|
||||
func (s *Server) OnInit(serve *grpc.Server) {
|
||||
grpc_pb.RegisterQgdzsServer(serve, s)
|
||||
s.query = repository.Query()
|
||||
}
|
||||
|
||||
func (s *Server) OnClose() {
|
||||
|
||||
@@ -2,9 +2,27 @@ package grpc_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
)
|
||||
|
||||
// 答题总数排行榜
|
||||
// 正确数量排行榜
|
||||
// 正确率排行榜
|
||||
// 错误数量排行榜
|
||||
// 错误率排行榜
|
||||
|
||||
var (
|
||||
scriptUpdateSha1 string
|
||||
scriptUpdate = `
|
||||
local key = KEYS[1]
|
||||
`
|
||||
)
|
||||
|
||||
// UpdateLeaderboard 更新排行榜
|
||||
func (s *Server) UpdateLeaderboard(ctx context.Context) error {
|
||||
if scriptUpdateSha1 == "" {
|
||||
scriptUpdateSha1 = redis.GetClient().ScriptLoad(ctx, scriptUpdate).Val()
|
||||
}
|
||||
redis.GetClient().EvalSha(ctx, scriptUpdateSha1, []string{"key"}, "value")
|
||||
return nil
|
||||
}
|
||||
|
||||
48
internal/grpc_server/server_point.go
Normal file
48
internal/grpc_server/server_point.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package grpc_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
)
|
||||
|
||||
// 模块 - 学识分
|
||||
|
||||
// GetPointRecord 获取学识分获取记录
|
||||
func (s *Server) GetPointRecord(ctx context.Context, req *grpc_pb.GetPointRecordReq) (*grpc_pb.GetPointRecordResp, error) {
|
||||
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||
return nil, http_resp.ParamError
|
||||
}
|
||||
records, count, err := repository.NewPointRecordsDao(ctx, s.query).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
resp := make([]*grpc_pb.GetPointRecordItem, 0)
|
||||
for _, record := range records {
|
||||
resp = append(resp, &grpc_pb.GetPointRecordItem{
|
||||
Source: record.Source,
|
||||
Point: record.Point,
|
||||
CreateTime: record.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
return &grpc_pb.GetPointRecordResp{
|
||||
Count: int32(count),
|
||||
Records: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetPoint 获取学识分
|
||||
func (s *Server) GetPoint(ctx context.Context, req *grpc_pb.GetPointReq) (*grpc_pb.GetPointResp, error) {
|
||||
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||
return nil, http_resp.ParamError
|
||||
}
|
||||
pointCard, err := repository.NewPointCardDao(ctx, s.query).FindPointByUserSn(req.USN)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
return &grpc_pb.GetPointResp{
|
||||
Point: pointCard.Point,
|
||||
}, nil
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/ai"
|
||||
@@ -28,7 +27,7 @@ var prompt = []string{`
|
||||
"question": "题目文本", // 简洁,30字以内
|
||||
"options": ["A. 选项1", "B. 选项2", "C. 选项3", "D. 选项4"], // 提供4个选项(A/B/C/D),其中仅1个正确
|
||||
"answer": "C", // 答案
|
||||
"explanation": "解析文本", // 200字以内,尽量幽默有趣
|
||||
"explanation": "解析文本", // 200字以内,尽量幽默有趣,不要在文本中说正确和错误,因为不知道用户选的哪个
|
||||
"category": "分类", // 尽量从上述分类中选择,你也可以增加,但是命名风格要类似
|
||||
"difficulty": 100, // 难度分 0 - 100
|
||||
}]
|
||||
@@ -55,17 +54,21 @@ type Question struct {
|
||||
}
|
||||
|
||||
func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQuestionReq) (*grpc_pb.GenerateQuestionResp, error) {
|
||||
categoryDao := repository.NewCategoryDao(ctx, redis.GetCacheClient())
|
||||
categoryDao := repository.NewCategoryDao(ctx, s.query, redis.GetCacheClient())
|
||||
category, err := categoryDao.FindAll()
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
categoryName := make([]string, 0)
|
||||
for _, c := range category {
|
||||
categoryName = append(categoryName, c.Category)
|
||||
}
|
||||
question := make([]*Question, 0)
|
||||
err = ai.NewAIClient(false, "", 0.9).
|
||||
RequestAI(
|
||||
[]string{
|
||||
fmt.Sprintf(prompt[0], time.Now().Format("2006-01-02 15:04:05"), category),
|
||||
fmt.Sprintf(prompt[1], req.Num, req.Category),
|
||||
fmt.Sprintf(prompt[0], time.Now().Format("2006-01-02 15:04:05"), categoryName),
|
||||
fmt.Sprintf(prompt[1], req.Num),
|
||||
fmt.Sprintf(prompt[2], req.Num),
|
||||
fmt.Sprintf(prompt[3], req.Num),
|
||||
fmt.Sprintf(prompt[4], req.Num),
|
||||
@@ -87,7 +90,7 @@ func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQues
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
|
||||
questionDao := repository.NewQuestionDao(ctx, redis.GetCacheClient())
|
||||
questionDao := repository.NewQuestionDao(ctx, s.query, redis.GetCacheClient())
|
||||
for _, q := range question {
|
||||
marshal, _ := json.Marshal(q.Options)
|
||||
categorySn, err := categoryDao.FindSnByName(q.Category)
|
||||
@@ -119,117 +122,3 @@ func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQues
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetQuestion 获取题目
|
||||
func (s *Server) GetQuestion(ctx context.Context, req *grpc_pb.GetQuestionReq) (*grpc_pb.GetQuestionResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx).FindByRandom(req.CategorySn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
|
||||
return &grpc_pb.GetQuestionResp{
|
||||
Sn: question.Sn,
|
||||
Question: question.Question,
|
||||
Options: options,
|
||||
Category: category,
|
||||
Difficulty: question.Difficulty,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetQuestionInfo 获取具体的题目
|
||||
func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx).FindBySn(req.QuestionSn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
|
||||
return &grpc_pb.GetQuestionInfoResp{
|
||||
Question: question.Question,
|
||||
Options: options,
|
||||
Category: category,
|
||||
Difficulty: question.Difficulty,
|
||||
Explanation: question.Explanation,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// AnswerQuestion 回答题目
|
||||
func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestionReq) (*grpc_pb.AnswerQuestionResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx).FindBySn(req.Sn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
// 保存答题记录
|
||||
if utils.ShouldBindUsn(ctx, &req.USN) {
|
||||
isCorrect := int32(0)
|
||||
if req.Answer == question.Answer {
|
||||
isCorrect = 1
|
||||
}
|
||||
_, _ = repository.NewRecordDao(ctx).Create(&model.Record{
|
||||
UserSn: req.USN,
|
||||
QuestionSn: question.Sn,
|
||||
Answer: req.Answer,
|
||||
IsCorrect: isCorrect,
|
||||
})
|
||||
}
|
||||
return &grpc_pb.AnswerQuestionResp{
|
||||
Answer: question.Answer,
|
||||
Explanation: question.Explanation,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetAllCategory 获取所有类目
|
||||
func (s *Server) GetAllCategory(ctx context.Context, req *grpc_pb.GetAllCategoryReq) (*grpc_pb.GetAllCategoryResp, error) {
|
||||
categoryList, err := repository.NewCategoryDao(ctx).FindAll()
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
categories := make([]*grpc_pb.GetAllCategoryItem, 0)
|
||||
for _, category := range categoryList {
|
||||
categories = append(categories, &grpc_pb.GetAllCategoryItem{
|
||||
Sn: category.Sn,
|
||||
Category: category.Category,
|
||||
})
|
||||
}
|
||||
return &grpc_pb.GetAllCategoryResp{
|
||||
Categories: categories,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetRecord 获取答题记录
|
||||
func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grpc_pb.GetRecordResp, error) {
|
||||
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||
return nil, http_resp.ParamError
|
||||
}
|
||||
records, count, err := repository.NewRecordDao(ctx).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
resp := make([]*grpc_pb.GetRecordItem, 0)
|
||||
for _, record := range records {
|
||||
resp = append(resp, &grpc_pb.GetRecordItem{
|
||||
QuestionSn: record.QuestionSn,
|
||||
Question: record.Question,
|
||||
Difficulty: record.Difficulty,
|
||||
Category: record.Category,
|
||||
QuestionAnswer: record.QuestionAnswer,
|
||||
Answer: record.Answer,
|
||||
CreateTime: record.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
return &grpc_pb.GetRecordResp{
|
||||
Count: int32(count),
|
||||
Records: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
61
internal/grpc_server/server_quickly.go
Normal file
61
internal/grpc_server/server_quickly.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package grpc_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
||||
)
|
||||
|
||||
// 玩法 - 随机答题
|
||||
|
||||
// QuicklyGetQuestion 获取题目
|
||||
func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGetQuestionReq) (*grpc_pb.QuicklyGetQuestionResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||
return &grpc_pb.QuicklyGetQuestionResp{
|
||||
Sn: question.Sn,
|
||||
Question: question.Question,
|
||||
Options: options,
|
||||
Category: category,
|
||||
Difficulty: question.Difficulty,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// QuicklyAnswerQuestion 回答题目
|
||||
func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *grpc_pb.QuicklyAnswerQuestionReq) (*grpc_pb.QuicklyAnswerQuestionResp, error) {
|
||||
utils.ShouldBindUsn(ctx, &req.USN)
|
||||
|
||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
// 保存答题记录
|
||||
if req.USN != 0 {
|
||||
kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{
|
||||
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||
USN: req.USN,
|
||||
QuestionSn: question.Sn,
|
||||
QuestionAnswer: question.Answer,
|
||||
Answer: req.Answer,
|
||||
})
|
||||
}
|
||||
return &grpc_pb.QuicklyAnswerQuestionResp{
|
||||
Answer: question.Answer,
|
||||
Explanation: question.Explanation,
|
||||
}, nil
|
||||
}
|
||||
71
internal/grpc_server/server_random.go
Normal file
71
internal/grpc_server/server_random.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package grpc_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
||||
)
|
||||
|
||||
// 玩法 - 随机答题
|
||||
|
||||
// RandomGetQuestion 获取题目
|
||||
func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQuestionReq) (*grpc_pb.RandomGetQuestionResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||
return &grpc_pb.RandomGetQuestionResp{
|
||||
Sn: question.Sn,
|
||||
Question: question.Question,
|
||||
Options: options,
|
||||
Category: category,
|
||||
Difficulty: question.Difficulty,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RandomAnswerQuestion 回答题目
|
||||
func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAnswerQuestionReq) (*grpc_pb.RandomAnswerQuestionResp, error) {
|
||||
utils.ShouldBindUsn(ctx, &req.USN)
|
||||
|
||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
// 保存答题记录
|
||||
if req.USN != 0 {
|
||||
kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{
|
||||
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||
USN: req.USN,
|
||||
QuestionSn: question.Sn,
|
||||
QuestionAnswer: question.Answer,
|
||||
Answer: req.Answer,
|
||||
})
|
||||
|
||||
// 随机答题正确给10分,错误不得分
|
||||
if req.Answer == question.Answer {
|
||||
kafka.NewProducer().Produce(ctx, &timer.TopicAddPoint{
|
||||
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||
Source: timer.AddPointSourceRandom,
|
||||
USN: req.USN,
|
||||
Point: 10,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &grpc_pb.RandomAnswerQuestionResp{
|
||||
Answer: question.Answer,
|
||||
Explanation: question.Explanation,
|
||||
}, nil
|
||||
}
|
||||
59
internal/grpc_server/server_record.go
Normal file
59
internal/grpc_server/server_record.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package grpc_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
)
|
||||
|
||||
// 模块 - 答题记录
|
||||
|
||||
// GetRecord 获取答题记录
|
||||
func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grpc_pb.GetRecordResp, error) {
|
||||
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||
return nil, http_resp.ParamError
|
||||
}
|
||||
records, count, err := repository.NewRecordDao(ctx, s.query).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
resp := make([]*grpc_pb.GetRecordItem, 0)
|
||||
for _, record := range records {
|
||||
resp = append(resp, &grpc_pb.GetRecordItem{
|
||||
QuestionSn: record.QuestionSn,
|
||||
Question: record.Question,
|
||||
Difficulty: record.Difficulty,
|
||||
Category: record.Category,
|
||||
QuestionAnswer: record.QuestionAnswer,
|
||||
Answer: record.Answer,
|
||||
CreateTime: record.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
return &grpc_pb.GetRecordResp{
|
||||
Count: int32(count),
|
||||
Records: resp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetQuestionInfo 获取具体的题目
|
||||
func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) {
|
||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.QuestionSn)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorsWrap(err)
|
||||
}
|
||||
options := make([]string, 0)
|
||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||
}
|
||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||
return &grpc_pb.GetQuestionInfoResp{
|
||||
Question: question.Question,
|
||||
Options: options,
|
||||
Category: category,
|
||||
Difficulty: question.Difficulty,
|
||||
Explanation: question.Explanation,
|
||||
}, nil
|
||||
}
|
||||
103
internal/timer/consumer.go
Normal file
103
internal/timer/consumer.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package timer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// !!!消费者必须做幂等!!!
|
||||
func startConsumer() {
|
||||
go kafka.NewConsumer().Consume([]kafka.Topic{
|
||||
&TopicQuestionAnswer{},
|
||||
&TopicAddPoint{},
|
||||
})
|
||||
}
|
||||
|
||||
type TopicQuestionAnswer struct {
|
||||
MessageSn int64 `json:"messageSn"`
|
||||
USN int64 `json:"usn"`
|
||||
QuestionSn int64 `json:"questionSn"`
|
||||
QuestionAnswer string `json:"questionAnswer"`
|
||||
Answer string `json:"answer"`
|
||||
}
|
||||
|
||||
func (t *TopicQuestionAnswer) Name() string {
|
||||
return "qgdzs.question.answer"
|
||||
}
|
||||
|
||||
func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error {
|
||||
log.Infof("Kafka consume topic: %v: %#+v", t.Name(), t)
|
||||
if t.USN == 0 || t.QuestionSn == 0 {
|
||||
return utils.ErrorsWrap(errors.New("invalid data"))
|
||||
}
|
||||
|
||||
// 答题记录
|
||||
isCorrect := int32(0)
|
||||
if t.QuestionAnswer == t.Answer {
|
||||
isCorrect = 1
|
||||
}
|
||||
_, err := repository.NewRecordDao(ctx, repository.Query()).Create(&model.Record{
|
||||
Sn: t.MessageSn,
|
||||
UserSn: t.USN,
|
||||
QuestionSn: t.QuestionSn,
|
||||
Answer: t.Answer,
|
||||
IsCorrect: isCorrect,
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return nil
|
||||
}
|
||||
return utils.ErrorsWrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type TopicAddPoint struct {
|
||||
MessageSn int64 `json:"messageSn"`
|
||||
Source AddPointSource `json:"source"`
|
||||
USN int64 `json:"usn"`
|
||||
Point int64 `json:"point"`
|
||||
}
|
||||
|
||||
type AddPointSource int32
|
||||
|
||||
const (
|
||||
AddPointSourceUnKnown = 0
|
||||
AddPointSourceRandom = 1
|
||||
AddPointSourceCategory = 2
|
||||
AddPointSourceQuickly = 3
|
||||
)
|
||||
|
||||
func (t *TopicAddPoint) Name() string {
|
||||
return "qgdzs.user.point"
|
||||
}
|
||||
|
||||
func (t *TopicAddPoint) OnMessage(ctx context.Context) error {
|
||||
log.Infof("Kafka consume topic: %v: %#+v", t.Name(), t)
|
||||
if t.USN == 0 || t.Point == 0 {
|
||||
return utils.ErrorsWrap(errors.New("invalid data"))
|
||||
}
|
||||
|
||||
// 积分记录 & 加分
|
||||
err := repository.NewPointRecordsDao(ctx, repository.Query()).CreateAndIncrPointCard(&model.PointRecord{
|
||||
Sn: t.MessageSn,
|
||||
UserSn: t.USN,
|
||||
Source: int32(t.Source),
|
||||
Point: t.Point,
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return nil
|
||||
}
|
||||
return utils.ErrorsWrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
19
internal/timer/timer.go
Normal file
19
internal/timer/timer.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package timer
|
||||
|
||||
import "github.com/robfig/cron/v3"
|
||||
|
||||
type Timer struct {
|
||||
c *cron.Cron
|
||||
}
|
||||
|
||||
func (t *Timer) Start() {
|
||||
t.c = cron.New()
|
||||
_, _ = t.c.AddFunc("0/5 * * * ?", func() {
|
||||
})
|
||||
t.c.Start()
|
||||
startConsumer()
|
||||
}
|
||||
|
||||
func (t *Timer) Stop() {
|
||||
t.c.Stop()
|
||||
}
|
||||
4
main.go
4
main.go
@@ -3,11 +3,15 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/app"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
||||
"github.com/judwhite/go-svc"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := config.LoadConfig(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err := svc.Run(&app.Program{}, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user