gs数据库接入gorm框架初步
This commit is contained in:
1 parent
a8b1e9002d
commit
688213e39f
22 files changed
+303
-288
No files matched your search
@@ -18,7 +18,7 @@ clean:
|
|||||||
# 构建服务器二进制文件
|
# 构建服务器二进制文件
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
mkdir -p bin && go build -ldflags "-X main.VERSION=$(VERSION)" -o ./bin/ ./cmd/...
|
mkdir -p bin && go build -ldflags "-X main.VERSION=$(VERSION) -X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" -o ./bin/ ./cmd/...
|
||||||
|
|
||||||
# 清理镜像
|
# 清理镜像
|
||||||
.PHONY: docker_clean
|
.PHONY: docker_clean
|
||||||
|
|||||||
+1
-1
@@ -10,12 +10,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/glebarez/sqlite"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
"gorm.io/driver/sqlite"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
gormlogger "gorm.io/gorm/logger"
|
gormlogger "gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -9,12 +9,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/glebarez/sqlite"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
"gorm.io/driver/sqlite"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
gormlogger "gorm.io/gorm/logger"
|
gormlogger "gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -55,12 +55,12 @@ require github.com/gorilla/websocket v1.4.2
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dengsgo/math-engine v0.0.0-20230823154425-78f211b48149
|
github.com/dengsgo/math-engine v0.0.0-20230823154425-78f211b48149
|
||||||
|
github.com/glebarez/sqlite v1.11.0
|
||||||
github.com/nats-io/nats-server/v2 v2.9.7
|
github.com/nats-io/nats-server/v2 v2.9.7
|
||||||
github.com/stretchr/testify v1.8.3
|
github.com/stretchr/testify v1.8.3
|
||||||
golang.org/x/net v0.10.0
|
golang.org/x/net v0.10.0
|
||||||
golang.org/x/sys v0.8.0
|
golang.org/x/sys v0.8.0
|
||||||
gorm.io/driver/mysql v1.5.7
|
gorm.io/driver/mysql v1.5.7
|
||||||
gorm.io/driver/sqlite v1.5.6
|
|
||||||
gorm.io/gorm v1.25.12
|
gorm.io/gorm v1.25.12
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -70,8 +70,10 @@ require (
|
|||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.14.0 // indirect
|
github.com/go-playground/validator/v10 v10.14.0 // indirect
|
||||||
@@ -79,6 +81,7 @@ require (
|
|||||||
github.com/go-stack/stack v1.8.0 // indirect
|
github.com/go-stack/stack v1.8.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
github.com/golang/snappy v0.0.1 // indirect
|
||||||
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
@@ -87,7 +90,6 @@ require (
|
|||||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||||
github.com/leodido/go-urn v1.2.4 // indirect
|
github.com/leodido/go-urn v1.2.4 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 // indirect
|
|
||||||
github.com/minio/highwayhash v1.0.2 // indirect
|
github.com/minio/highwayhash v1.0.2 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
@@ -97,6 +99,7 @@ require (
|
|||||||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||||
@@ -111,4 +114,8 @@ require (
|
|||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
modernc.org/libc v1.22.5 // indirect
|
||||||
|
modernc.org/mathutil v1.5.0 // indirect
|
||||||
|
modernc.org/memory v1.5.0 // indirect
|
||||||
|
modernc.org/sqlite v1.23.1 // indirect
|
||||||
)
|
)
|
||||||
@@ -20,6 +20,8 @@ github.com/dengsgo/math-engine v0.0.0-20230823154425-78f211b48149 h1:TkVfb0s14IU
|
|||||||
github.com/dengsgo/math-engine v0.0.0-20230823154425-78f211b48149/go.mod h1:zkR27k4K0I8FS6rkEd8qBhPeS8i3X2FKfvSPdF64OpQ=
|
github.com/dengsgo/math-engine v0.0.0-20230823154425-78f211b48149/go.mod h1:zkR27k4K0I8FS6rkEd8qBhPeS8i3X2FKfvSPdF64OpQ=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
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/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||||
@@ -27,6 +29,10 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
|
|||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
||||||
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
||||||
|
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
|
||||||
|
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
|
||||||
|
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
|
||||||
|
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
|
||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
@@ -52,6 +58,9 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/hjson/hjson-go/v4 v4.2.0 h1:GBa/BfCg/68J0dB/ztAYJtVecXpalG4nZkY4UusGZXQ=
|
github.com/hjson/hjson-go/v4 v4.2.0 h1:GBa/BfCg/68J0dB/ztAYJtVecXpalG4nZkY4UusGZXQ=
|
||||||
@@ -81,8 +90,6 @@ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
|||||||
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
|
||||||
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
|
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
|
||||||
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
|
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
@@ -112,6 +119,9 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
||||||
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
||||||
@@ -203,9 +213,15 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
||||||
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||||
gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
|
|
||||||
gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
|
|
||||||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
|
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
|
||||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
||||||
|
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
|
||||||
|
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
|
||||||
|
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
|
||||||
|
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||||
|
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
|
||||||
|
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||||
|
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
|
||||||
|
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
|
||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||||
+74
-16
@@ -2,19 +2,27 @@ package dao
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"hk4e/common/config"
|
"hk4e/common/config"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/glebarez/sqlite"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
gormlogger "gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dao struct {
|
type Dao struct {
|
||||||
mongo *mongo.Client
|
mongo *mongo.Client
|
||||||
db *mongo.Database
|
mongoDb *mongo.Database
|
||||||
|
gormDb *gorm.DB
|
||||||
redis *redis.Client
|
redis *redis.Client
|
||||||
redisCluster *redis.ClusterClient
|
redisCluster *redis.ClusterClient
|
||||||
}
|
}
|
||||||
@@ -22,19 +30,65 @@ type Dao struct {
|
|||||||
func NewDao() (*Dao, error) {
|
func NewDao() (*Dao, error) {
|
||||||
r := new(Dao)
|
r := new(Dao)
|
||||||
|
|
||||||
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url).SetMinPoolSize(1).SetMaxPoolSize(10)
|
if strings.Contains(config.GetConfig().Database.Url, "mongodb://") {
|
||||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
clientOptions := options.Client().ApplyURI(config.GetConfig().Database.Url)
|
||||||
if err != nil {
|
clientOptions = clientOptions.SetMinPoolSize(10)
|
||||||
logger.Error("mongo connect error: %v", err)
|
clientOptions = clientOptions.SetMaxPoolSize(100)
|
||||||
return nil, err
|
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("mongo connect error: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = client.Ping(context.TODO(), readpref.Primary())
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("mongo ping error: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.mongo = client
|
||||||
|
r.mongoDb = client.Database("gs_hk4e")
|
||||||
|
} else {
|
||||||
|
if strings.Contains(config.GetConfig().Database.Url, "mysql://") {
|
||||||
|
dsn := strings.ReplaceAll(config.GetConfig().Database.Url, "mysql://", "")
|
||||||
|
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||||
|
Logger: gormlogger.Default.LogMode(gormlogger.Info),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("gorm open error: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.gormDb = db
|
||||||
|
sqlDb, err := db.DB()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("sql db open error: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sqlDb.SetMaxIdleConns(10)
|
||||||
|
sqlDb.SetMaxOpenConns(100)
|
||||||
|
sqlDb.SetConnMaxLifetime(time.Hour)
|
||||||
|
} else if strings.Contains(config.GetConfig().Database.Url, "sqlite://") {
|
||||||
|
dsn := strings.ReplaceAll(config.GetConfig().Database.Url, "sqlite://", "")
|
||||||
|
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{
|
||||||
|
Logger: gormlogger.Default.LogMode(gormlogger.Info),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("gorm open error: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r.gormDb = db
|
||||||
|
} else {
|
||||||
|
err := errors.New(fmt.Sprintf("not support db type, url: %v", config.GetConfig().Database.Url))
|
||||||
|
logger.Error("%v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tableList := []any{new(PlayerGorm), new(ChatMsgGorm), new(SceneBlockGorm)}
|
||||||
|
for _, table := range tableList {
|
||||||
|
err := r.gormDb.AutoMigrate(table)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("auto migrate error: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = client.Ping(context.TODO(), readpref.Primary())
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("mongo ping error: %v", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
r.mongo = client
|
|
||||||
r.db = client.Database("gs_hk4e")
|
|
||||||
|
|
||||||
if !config.GetConfig().Hk4e.StandaloneModeEnable {
|
if !config.GetConfig().Hk4e.StandaloneModeEnable {
|
||||||
r.redis = nil
|
r.redis = nil
|
||||||
@@ -57,6 +111,7 @@ func NewDao() (*Dao, error) {
|
|||||||
MinIdleConns: 1,
|
MinIdleConns: 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
var err error = nil
|
||||||
if r.redisCluster != nil {
|
if r.redisCluster != nil {
|
||||||
err = r.redisCluster.Ping(context.TODO()).Err()
|
err = r.redisCluster.Ping(context.TODO()).Err()
|
||||||
} else {
|
} else {
|
||||||
@@ -72,12 +127,15 @@ func NewDao() (*Dao, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) CloseDao() {
|
func (d *Dao) CloseDao() {
|
||||||
err := d.mongo.Disconnect(context.TODO())
|
if d.mongo != nil {
|
||||||
if err != nil {
|
err := d.mongo.Disconnect(context.TODO())
|
||||||
logger.Error("mongo close error: %v", err)
|
if err != nil {
|
||||||
|
logger.Error("mongo close error: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !config.GetConfig().Hk4e.StandaloneModeEnable {
|
if !config.GetConfig().Hk4e.StandaloneModeEnable {
|
||||||
|
var err error = nil
|
||||||
if d.redisCluster != nil {
|
if d.redisCluster != nil {
|
||||||
err = d.redisCluster.Close()
|
err = d.redisCluster.Close()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"hk4e/gs/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PlayerGorm struct {
|
||||||
|
Uid uint32 `gorm:"column:uid;type:bigint(20);primaryKey"`
|
||||||
|
Data []byte `gorm:"column:data;type:longblob"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p PlayerGorm) TableName() string {
|
||||||
|
return "player"
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChatMsgGorm struct {
|
||||||
|
ID uint32 `gorm:"column:id;type:bigint(20);primaryKey"`
|
||||||
|
Sequence uint32 `gorm:"column:sequence;type:bigint(20)"`
|
||||||
|
Time uint32 `gorm:"column:time;type:bigint(20)"`
|
||||||
|
Uid uint32 `gorm:"column:uid;type:bigint(20)"`
|
||||||
|
ToUid uint32 `gorm:"column:to_uid;type:bigint(20)"`
|
||||||
|
IsRead bool `gorm:"column:is_read;type:tinyint(1)"`
|
||||||
|
MsgType uint8 `gorm:"column:msg_type;type:tinyint(1)"`
|
||||||
|
Text string `gorm:"column:text;type:text"`
|
||||||
|
Icon uint32 `gorm:"column:icon;type:bigint(20)"`
|
||||||
|
IsDelete bool `gorm:"column:is_delete;type:tinyint(1)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c ChatMsgGorm) TableName() string {
|
||||||
|
return "chat_msg"
|
||||||
|
}
|
||||||
|
|
||||||
|
type SceneBlockGorm struct {
|
||||||
|
Uid uint32 `gorm:"column:uid;type:bigint(20)"`
|
||||||
|
BlockId uint32 `gorm:"column:block_id;type:bigint(20)"`
|
||||||
|
Data []byte `gorm:"column:data;type:longblob"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SceneBlockGorm) TableName() string {
|
||||||
|
return "scene_block"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) InsertPlayerGorm(player *model.Player) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) InsertPlayerListGorm(playerList []*model.Player) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) DeletePlayerGorm(playerId uint32) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) DeletePlayerListGorm(playerIdList []uint32) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) UpdatePlayerGorm(player *model.Player) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) UpdatePlayerListGorm(playerList []*model.Player) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) QueryPlayerByIdGorm(playerId uint32) (*model.Player, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) QueryPlayerListGorm() ([]*model.Player, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) InsertChatMsgGorm(chatMsg *model.ChatMsg) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) DeleteUpdateChatMsgByUidGorm(uid uint32) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) UpdateChatMsgByUidAndToUidActionReadGorm(uid uint32, toUid uint32) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) QueryChatMsgListByUidGorm(uid uint32) ([]*model.ChatMsg, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) InsertSceneBlockGorm(sceneBlock *model.SceneBlock) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) UpdateSceneBlockGorm(sceneBlock *model.SceneBlock) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dao) QuerySceneBlockByUidAndBlockIdGorm(uid uint32, blockId uint32) (*model.SceneBlock, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
+93
-260
@@ -7,7 +7,6 @@ import (
|
|||||||
"hk4e/gs/model"
|
"hk4e/gs/model"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
)
|
)
|
||||||
@@ -17,7 +16,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (d *Dao) InsertPlayer(player *model.Player) error {
|
func (d *Dao) InsertPlayer(player *model.Player) error {
|
||||||
db := d.db.Collection("player")
|
if d.mongo == nil {
|
||||||
|
return d.InsertPlayerGorm(player)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("player")
|
||||||
_, err := db.InsertOne(context.TODO(), player)
|
_, err := db.InsertOne(context.TODO(), player)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -25,29 +27,14 @@ func (d *Dao) InsertPlayer(player *model.Player) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) InsertChatMsg(chatMsg *model.ChatMsg) error {
|
|
||||||
db := d.db.Collection("player_chat_msg")
|
|
||||||
_, err := db.InsertOne(context.TODO(), chatMsg)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) InsertSceneBlock(sceneBlock *model.SceneBlock) error {
|
|
||||||
db := d.db.Collection("player_scene_block")
|
|
||||||
_, err := db.InsertOne(context.TODO(), sceneBlock)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) InsertPlayerList(playerList []*model.Player) error {
|
func (d *Dao) InsertPlayerList(playerList []*model.Player) error {
|
||||||
|
if d.mongo == nil {
|
||||||
|
return d.InsertPlayerListGorm(playerList)
|
||||||
|
}
|
||||||
if len(playerList) == 0 {
|
if len(playerList) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
db := d.db.Collection("player")
|
db := d.mongoDb.Collection("player")
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
modelOperateList := make([]mongo.WriteModel, 0)
|
||||||
for _, player := range playerList {
|
for _, player := range playerList {
|
||||||
modelOperate := mongo.NewInsertOneModel().SetDocument(player)
|
modelOperate := mongo.NewInsertOneModel().SetDocument(player)
|
||||||
@@ -60,42 +47,11 @@ func (d *Dao) InsertPlayerList(playerList []*model.Player) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) InsertChatMsgList(chatMsgList []*model.ChatMsg) error {
|
|
||||||
if len(chatMsgList) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
db := d.db.Collection("player_chat_msg")
|
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
|
||||||
for _, chatMsg := range chatMsgList {
|
|
||||||
modelOperate := mongo.NewInsertOneModel().SetDocument(chatMsg)
|
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
|
||||||
}
|
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) InsertSceneBlockList(sceneBlockList []*model.SceneBlock) error {
|
|
||||||
if len(sceneBlockList) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
db := d.db.Collection("player_scene_block")
|
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
|
||||||
for _, sceneBlock := range sceneBlockList {
|
|
||||||
modelOperate := mongo.NewInsertOneModel().SetDocument(sceneBlock)
|
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
|
||||||
}
|
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) DeletePlayer(playerId uint32) error {
|
func (d *Dao) DeletePlayer(playerId uint32) error {
|
||||||
db := d.db.Collection("player")
|
if d.mongo == nil {
|
||||||
|
return d.DeletePlayerGorm(playerId)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("player")
|
||||||
_, err := db.DeleteOne(context.TODO(), bson.D{{"player_id", playerId}})
|
_, err := db.DeleteOne(context.TODO(), bson.D{{"player_id", playerId}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -103,29 +59,14 @@ func (d *Dao) DeletePlayer(playerId uint32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) DeleteChatMsg(id primitive.ObjectID) error {
|
|
||||||
db := d.db.Collection("player_chat_msg")
|
|
||||||
_, err := db.DeleteOne(context.TODO(), bson.D{{"_id", id}})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) DeleteSceneBlock(id primitive.ObjectID) error {
|
|
||||||
db := d.db.Collection("player_scene_block")
|
|
||||||
_, err := db.DeleteOne(context.TODO(), bson.D{{"_id", id}})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) DeletePlayerList(playerIdList []uint32) error {
|
func (d *Dao) DeletePlayerList(playerIdList []uint32) error {
|
||||||
|
if d.mongo == nil {
|
||||||
|
return d.DeletePlayerListGorm(playerIdList)
|
||||||
|
}
|
||||||
if len(playerIdList) == 0 {
|
if len(playerIdList) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
db := d.db.Collection("player")
|
db := d.mongoDb.Collection("player")
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
modelOperateList := make([]mongo.WriteModel, 0)
|
||||||
for _, playerId := range playerIdList {
|
for _, playerId := range playerIdList {
|
||||||
modelOperate := mongo.NewDeleteOneModel().SetFilter(bson.D{{"player_id", playerId}})
|
modelOperate := mongo.NewDeleteOneModel().SetFilter(bson.D{{"player_id", playerId}})
|
||||||
@@ -138,42 +79,11 @@ func (d *Dao) DeletePlayerList(playerIdList []uint32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) DeleteChatMsgList(idList []primitive.ObjectID) error {
|
|
||||||
if len(idList) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
db := d.db.Collection("player_chat_msg")
|
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
|
||||||
for _, id := range idList {
|
|
||||||
modelOperate := mongo.NewDeleteOneModel().SetFilter(bson.D{{"_id", id}})
|
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
|
||||||
}
|
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) DeleteSceneBlockList(idList []primitive.ObjectID) error {
|
|
||||||
if len(idList) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
db := d.db.Collection("player_scene_block")
|
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
|
||||||
for _, id := range idList {
|
|
||||||
modelOperate := mongo.NewDeleteOneModel().SetFilter(bson.D{{"_id", id}})
|
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
|
||||||
}
|
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) UpdatePlayer(player *model.Player) error {
|
func (d *Dao) UpdatePlayer(player *model.Player) error {
|
||||||
db := d.db.Collection("player")
|
if d.mongo == nil {
|
||||||
|
return d.UpdatePlayerGorm(player)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("player")
|
||||||
_, err := db.UpdateMany(
|
_, err := db.UpdateMany(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{{"player_id", player.PlayerId}},
|
bson.D{{"player_id", player.PlayerId}},
|
||||||
@@ -185,37 +95,14 @@ func (d *Dao) UpdatePlayer(player *model.Player) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) UpdateChatMsg(chatMsg *model.ChatMsg) error {
|
|
||||||
db := d.db.Collection("player_chat_msg")
|
|
||||||
_, err := db.UpdateMany(
|
|
||||||
context.TODO(),
|
|
||||||
bson.D{{"_id", chatMsg.ID}},
|
|
||||||
bson.D{{"$set", chatMsg}},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) UpdateSceneBlock(sceneBlock *model.SceneBlock) error {
|
|
||||||
db := d.db.Collection("player_scene_block")
|
|
||||||
_, err := db.UpdateMany(
|
|
||||||
context.TODO(),
|
|
||||||
bson.D{{"_id", sceneBlock.ID}},
|
|
||||||
bson.D{{"$set", sceneBlock}},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) UpdatePlayerList(playerList []*model.Player) error {
|
func (d *Dao) UpdatePlayerList(playerList []*model.Player) error {
|
||||||
|
if d.mongo == nil {
|
||||||
|
return d.UpdatePlayerListGorm(playerList)
|
||||||
|
}
|
||||||
if len(playerList) == 0 {
|
if len(playerList) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
db := d.db.Collection("player")
|
db := d.mongoDb.Collection("player")
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
modelOperateList := make([]mongo.WriteModel, 0)
|
||||||
for _, player := range playerList {
|
for _, player := range playerList {
|
||||||
modelOperate := mongo.NewUpdateManyModel().SetFilter(bson.D{{"player_id", player.PlayerId}}).SetUpdate(bson.D{{"$set", player}})
|
modelOperate := mongo.NewUpdateManyModel().SetFilter(bson.D{{"player_id", player.PlayerId}}).SetUpdate(bson.D{{"$set", player}})
|
||||||
@@ -228,42 +115,11 @@ func (d *Dao) UpdatePlayerList(playerList []*model.Player) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) UpdateChatMsgList(chatMsgList []*model.ChatMsg) error {
|
|
||||||
if len(chatMsgList) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
db := d.db.Collection("player_chat_msg")
|
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
|
||||||
for _, chatMsg := range chatMsgList {
|
|
||||||
modelOperate := mongo.NewUpdateManyModel().SetFilter(bson.D{{"_id", chatMsg.ID}}).SetUpdate(bson.D{{"$set", chatMsg}})
|
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
|
||||||
}
|
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) UpdateSceneBlockList(sceneBlockList []*model.SceneBlock) error {
|
|
||||||
if len(sceneBlockList) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
db := d.db.Collection("player_scene_block")
|
|
||||||
modelOperateList := make([]mongo.WriteModel, 0)
|
|
||||||
for _, sceneBlock := range sceneBlockList {
|
|
||||||
modelOperate := mongo.NewUpdateManyModel().SetFilter(bson.D{{"_id", sceneBlock.ID}}).SetUpdate(bson.D{{"$set", sceneBlock}})
|
|
||||||
modelOperateList = append(modelOperateList, modelOperate)
|
|
||||||
}
|
|
||||||
_, err := db.BulkWrite(context.TODO(), modelOperateList)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) QueryPlayerById(playerId uint32) (*model.Player, error) {
|
func (d *Dao) QueryPlayerById(playerId uint32) (*model.Player, error) {
|
||||||
db := d.db.Collection("player")
|
if d.mongo == nil {
|
||||||
|
return d.QueryPlayerByIdGorm(playerId)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("player")
|
||||||
result := db.FindOne(
|
result := db.FindOne(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{{"player_id", playerId}},
|
bson.D{{"player_id", playerId}},
|
||||||
@@ -280,44 +136,11 @@ func (d *Dao) QueryPlayerById(playerId uint32) (*model.Player, error) {
|
|||||||
return player, nil
|
return player, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) QueryChatMsgById(id primitive.ObjectID) (*model.ChatMsg, error) {
|
|
||||||
db := d.db.Collection("player_chat_msg")
|
|
||||||
result := db.FindOne(
|
|
||||||
context.TODO(),
|
|
||||||
bson.D{{"_id", id}},
|
|
||||||
)
|
|
||||||
chatMsg := new(model.ChatMsg)
|
|
||||||
err := result.Decode(chatMsg)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
|
||||||
return nil, nil
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return chatMsg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) QuerySceneBlockById(id primitive.ObjectID) (*model.SceneBlock, error) {
|
|
||||||
db := d.db.Collection("player_scene_block")
|
|
||||||
result := db.FindOne(
|
|
||||||
context.TODO(),
|
|
||||||
bson.D{{"_id", id}},
|
|
||||||
)
|
|
||||||
sceneBlock := new(model.SceneBlock)
|
|
||||||
err := result.Decode(sceneBlock)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
|
||||||
return nil, nil
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sceneBlock, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Dao) QueryPlayerList() ([]*model.Player, error) {
|
func (d *Dao) QueryPlayerList() ([]*model.Player, error) {
|
||||||
db := d.db.Collection("player")
|
if d.mongo == nil {
|
||||||
|
return d.QueryPlayerListGorm()
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("player")
|
||||||
find, err := db.Find(
|
find, err := db.Find(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{},
|
bson.D{},
|
||||||
@@ -337,50 +160,63 @@ func (d *Dao) QueryPlayerList() ([]*model.Player, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) QueryChatMsgList() ([]*model.ChatMsg, error) {
|
func (d *Dao) InsertChatMsg(chatMsg *model.ChatMsg) error {
|
||||||
db := d.db.Collection("player_chat_msg")
|
if d.mongo == nil {
|
||||||
find, err := db.Find(
|
return d.InsertChatMsgGorm(chatMsg)
|
||||||
context.TODO(),
|
}
|
||||||
bson.D{},
|
db := d.mongoDb.Collection("chat_msg")
|
||||||
)
|
_, err := db.InsertOne(context.TODO(), chatMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
result := make([]*model.ChatMsg, 0)
|
return nil
|
||||||
for find.Next(context.TODO()) {
|
|
||||||
item := new(model.ChatMsg)
|
|
||||||
err = find.Decode(item)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result = append(result, item)
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) QuerySceneBlockList() ([]*model.SceneBlock, error) {
|
func (d *Dao) DeleteUpdateChatMsgByUid(uid uint32) error {
|
||||||
db := d.db.Collection("player_scene_block")
|
if d.mongo == nil {
|
||||||
find, err := db.Find(
|
return d.DeleteUpdateChatMsgByUidGorm(uid)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("chat_msg")
|
||||||
|
_, err := db.UpdateMany(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{},
|
bson.D{{"$or", []bson.D{{{"to_uid", uid}}, {{"uid", uid}}}}},
|
||||||
|
bson.D{{"$set", bson.D{{"is_delete", true}}}},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
result := make([]*model.SceneBlock, 0)
|
return nil
|
||||||
for find.Next(context.TODO()) {
|
}
|
||||||
item := new(model.SceneBlock)
|
|
||||||
err = find.Decode(item)
|
func (d *Dao) UpdateChatMsgByUidAndToUidActionRead(uid uint32, toUid uint32) error {
|
||||||
if err != nil {
|
if d.mongo == nil {
|
||||||
return nil, err
|
return d.UpdateChatMsgByUidAndToUidActionReadGorm(uid, toUid)
|
||||||
}
|
|
||||||
result = append(result, item)
|
|
||||||
}
|
}
|
||||||
return result, nil
|
db := d.mongoDb.Collection("chat_msg")
|
||||||
|
_, err := db.UpdateMany(
|
||||||
|
context.TODO(),
|
||||||
|
bson.D{{"to_uid", uid}, {"uid", toUid}},
|
||||||
|
bson.D{{"$set", bson.D{{"is_read", true}}}},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = db.UpdateMany(
|
||||||
|
context.TODO(),
|
||||||
|
bson.D{{"uid", uid}, {"to_uid", toUid}},
|
||||||
|
bson.D{{"$set", bson.D{{"is_read", true}}}},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) QueryChatMsgListByUid(uid uint32) ([]*model.ChatMsg, error) {
|
func (d *Dao) QueryChatMsgListByUid(uid uint32) ([]*model.ChatMsg, error) {
|
||||||
db := d.db.Collection("player_chat_msg")
|
if d.mongo == nil {
|
||||||
|
return d.QueryChatMsgListByUidGorm(uid)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("chat_msg")
|
||||||
result := make([]*model.ChatMsg, 0)
|
result := make([]*model.ChatMsg, 0)
|
||||||
find, err := db.Find(
|
find, err := db.Find(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
@@ -407,33 +243,27 @@ func (d *Dao) QueryChatMsgListByUid(uid uint32) ([]*model.ChatMsg, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) ReadUpdateChatMsgByUid(uid uint32, targetUid uint32) error {
|
func (d *Dao) InsertSceneBlock(sceneBlock *model.SceneBlock) error {
|
||||||
db := d.db.Collection("player_chat_msg")
|
if d.mongo == nil {
|
||||||
_, err := db.UpdateMany(
|
return d.InsertSceneBlockGorm(sceneBlock)
|
||||||
context.TODO(),
|
|
||||||
bson.D{{"to_uid", uid}, {"uid", targetUid}},
|
|
||||||
bson.D{{"$set", bson.D{{"is_read", true}}}},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
_, err = db.UpdateMany(
|
db := d.mongoDb.Collection("scene_block")
|
||||||
context.TODO(),
|
_, err := db.InsertOne(context.TODO(), sceneBlock)
|
||||||
bson.D{{"uid", uid}, {"to_uid", targetUid}},
|
|
||||||
bson.D{{"$set", bson.D{{"is_read", true}}}},
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) DeleteAllUpdateChatMsgByUid(uid uint32) error {
|
func (d *Dao) UpdateSceneBlock(sceneBlock *model.SceneBlock) error {
|
||||||
db := d.db.Collection("player_chat_msg")
|
if d.mongo == nil {
|
||||||
|
return d.UpdateSceneBlockGorm(sceneBlock)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("scene_block")
|
||||||
_, err := db.UpdateMany(
|
_, err := db.UpdateMany(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{{"$or", []bson.D{{{"to_uid", uid}}, {{"uid", uid}}}}},
|
bson.D{{"_id", sceneBlock.ID}},
|
||||||
bson.D{{"$set", bson.D{{"is_delete", true}}}},
|
bson.D{{"$set", sceneBlock}},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -442,7 +272,10 @@ func (d *Dao) DeleteAllUpdateChatMsgByUid(uid uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dao) QuerySceneBlockByUidAndBlockId(uid uint32, blockId uint32) (*model.SceneBlock, error) {
|
func (d *Dao) QuerySceneBlockByUidAndBlockId(uid uint32, blockId uint32) (*model.SceneBlock, error) {
|
||||||
db := d.db.Collection("player_scene_block")
|
if d.mongo == nil {
|
||||||
|
return d.QuerySceneBlockByUidAndBlockIdGorm(uid, blockId)
|
||||||
|
}
|
||||||
|
db := d.mongoDb.Collection("scene_block")
|
||||||
result := db.FindOne(
|
result := db.FindOne(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
bson.D{{"$and", []bson.D{{{"uid", uid}}, {{"block_id", blockId}}}}},
|
bson.D{{"$and", []bson.D{{{"uid", uid}}, {{"block_id", blockId}}}}},
|
||||||
|
|||||||
@@ -815,7 +815,7 @@ func (u *UserManager) SaveUserChatMsgToDbSync(chatMsg *model.ChatMsg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserManager) ReadUserChatMsgToDbSync(uid uint32, targetUid uint32) {
|
func (u *UserManager) ReadUserChatMsgToDbSync(uid uint32, targetUid uint32) {
|
||||||
err := u.db.ReadUpdateChatMsgByUid(uid, targetUid)
|
err := u.db.UpdateChatMsgByUidAndToUidActionRead(uid, targetUid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("read chat msg error: %v", err)
|
logger.Error("read chat msg error: %v", err)
|
||||||
return
|
return
|
||||||
@@ -823,7 +823,7 @@ func (u *UserManager) ReadUserChatMsgToDbSync(uid uint32, targetUid uint32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserManager) DeleteUserAllChatMsgToDbSync(uid uint32) {
|
func (u *UserManager) DeleteUserAllChatMsgToDbSync(uid uint32) {
|
||||||
err := u.db.DeleteAllUpdateChatMsgByUid(uid)
|
err := u.db.DeleteUpdateChatMsgByUid(uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("delete chat msg error: %v", err)
|
logger.Error("delete chat msg error: %v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -9,11 +9,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/glebarez/sqlite"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
"gorm.io/driver/sqlite"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
gormlogger "gorm.io/gorm/logger"
|
gormlogger "gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user