上传db系统注册

This commit is contained in:
liwei1dao 2022-06-01 10:08:24 +08:00
parent f1a0a17d8f
commit 866cbf7858
13 changed files with 253 additions and 6 deletions

View File

@ -22,6 +22,9 @@ sys:
cache: #缓存系统
Redis_Addr: ["10.0.0.9:9001","10.0.0.9:9002","10.0.0.9:9003","10.0.1.45:9004","10.0.1.45:9005","10.0.1.45:9006"]
Redis_Password: ""
db: #存储系统
MongodbUrl: "mongodb://admin:123456@10.0.0.9:27018"
MongodbDatabase: "dreamfactory"
#模块配置
modules:

View File

@ -22,7 +22,9 @@ sys:
cache: #缓存系统
Redis_Addr: ["10.0.0.9:9001","10.0.0.9:9002","10.0.0.9:9003","10.0.1.45:9004","10.0.1.45:9005","10.0.1.45:9006"]
Redis_Password: ""
db: #存储系统
MongodbUrl: "mongodb://admin:123456@10.0.0.9:27018"
MongodbDatabase: "dreamfactory"
#模块配置
modules:
SM_WebModule:

8
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/aliyun/alibaba-cloud-sdk-go v1.61.885 // indirect
github.com/apache/thrift v0.16.0 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/aws/aws-sdk-go v1.34.28 // indirect
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 // indirect
github.com/cenk/backoff v2.2.1+incompatible // indirect
@ -33,6 +34,7 @@ require (
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.1 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
@ -52,6 +54,7 @@ require (
github.com/juju/ratelimit v1.0.1 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/kavu/go_reuseport v1.5.0 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/klauspost/reedsolomon v1.9.16 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
@ -95,7 +98,12 @@ require (
github.com/valyala/fastrand v1.1.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/xtaci/kcp-go v5.4.20+incompatible // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.5.1 // indirect
go.opentelemetry.io/otel v1.6.3 // indirect
go.opentelemetry.io/otel/trace v1.6.3 // indirect
go.uber.org/atomic v1.7.0 // indirect

9
go.sum
View File

@ -94,6 +94,7 @@ github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aws/aws-sdk-go v1.32.6/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.28 h1:sscPpn/Ns3i0F4HPEWAVcwdIRaZZCuL7llJ2/60yPIk=
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
@ -222,6 +223,7 @@ github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-redis/redis_rate/v9 v9.1.2/go.mod h1:oam2de2apSgRG8aJzwJddXbNu91Iyz1m8IKJE2vpvlQ=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
@ -481,6 +483,7 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.10.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
@ -777,6 +780,7 @@ github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7S
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b h1:fj5tQ8acgNUr6O8LEplsxDhUIe2573iLkJc+PqnzZTI=
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
@ -802,13 +806,17 @@ github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/wolfogre/go-pprof-practice v0.0.0-20190402114113-8ce266a210ee/go.mod h1:bwtOR7TyudY1IW9h5rVzpkyOkcwPPxinKAxIrdMnN+Q=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
github.com/xtaci/kcp-go v5.4.20+incompatible h1:TN1uey3Raw0sTz0Fg8GkfM0uH3YwzhnZWQ1bABv5xAg=
github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE=
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 h1:EWU6Pktpas0n8lLQwDsRyZfmkPeRbdgPtW609es+/9E=
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37/go.mod h1:HpMP7DB2CyokmAh4lp0EQnnWhmycP/TvwBGzvuie+H0=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@ -819,6 +827,7 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.mongodb.org/mongo-driver v1.5.1 h1:9nOVLGDfOaZ9R0tBumx/BcuqkbFpyTCU2r/Po7A2azI=
go.mongodb.org/mongo-driver v1.5.1/go.mod h1:gRXCHX4Jo7J0IJ1oDQyUxF7jfy19UfxniMS4xxMmUqw=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=

View File

@ -9,3 +9,10 @@ message Cache_UserData {
string Email = 5;
string Password = 6;
}
message DB_UserData {
uint32 UserId = 1; //tags:{bson:"_id"}Id
string NiceName = 2;
string Email = 3;
string Password = 4;
}

View File

@ -107,6 +107,77 @@ func (x *Cache_UserData) GetPassword() string {
return ""
}
type DB_UserData struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UserId uint32 `protobuf:"varint,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}动态Id
NiceName string `protobuf:"bytes,2,opt,name=NiceName,proto3" json:"NiceName,omitempty"`
Email string `protobuf:"bytes,3,opt,name=Email,proto3" json:"Email,omitempty"`
Password string `protobuf:"bytes,4,opt,name=Password,proto3" json:"Password,omitempty"`
}
func (x *DB_UserData) Reset() {
*x = DB_UserData{}
if protoimpl.UnsafeEnabled {
mi := &file_user_db_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DB_UserData) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DB_UserData) ProtoMessage() {}
func (x *DB_UserData) ProtoReflect() protoreflect.Message {
mi := &file_user_db_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DB_UserData.ProtoReflect.Descriptor instead.
func (*DB_UserData) Descriptor() ([]byte, []int) {
return file_user_db_proto_rawDescGZIP(), []int{1}
}
func (x *DB_UserData) GetUserId() uint32 {
if x != nil {
return x.UserId
}
return 0
}
func (x *DB_UserData) GetNiceName() string {
if x != nil {
return x.NiceName
}
return ""
}
func (x *DB_UserData) GetEmail() string {
if x != nil {
return x.Email
}
return ""
}
func (x *DB_UserData) GetPassword() string {
if x != nil {
return x.Password
}
return ""
}
var File_user_db_proto protoreflect.FileDescriptor
var file_user_db_proto_rawDesc = []byte{
@ -123,8 +194,15 @@ var file_user_db_proto_rawDesc = []byte{
0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f,
0x72, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f,
0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
0x72, 0x64, 0x22, 0x73, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74,
0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63,
0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63,
0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03,
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x50,
0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50,
0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -139,9 +217,10 @@ func file_user_db_proto_rawDescGZIP() []byte {
return file_user_db_proto_rawDescData
}
var file_user_db_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_user_db_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_user_db_proto_goTypes = []interface{}{
(*Cache_UserData)(nil), // 0: Cache_UserData
(*DB_UserData)(nil), // 1: DB_UserData
}
var file_user_db_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
@ -169,6 +248,18 @@ func file_user_db_proto_init() {
return nil
}
}
file_user_db_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DB_UserData); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -176,7 +267,7 @@ func file_user_db_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_user_db_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},

View File

@ -3,6 +3,7 @@ package services
import (
"fmt"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/db"
"github.com/liwei1dao/lego/base/rpcx"
"github.com/liwei1dao/lego/sys/log"
@ -19,4 +20,9 @@ func (this *ServiceBase) InitSys() {
} else {
log.Infof("init sys.cache success!")
}
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
} else {
log.Infof("init sys.db success!")
}
}

7
sys/cache/core.go vendored
View File

@ -1,7 +1,10 @@
package cache
import "go_dreamfactory/pb"
type (
ISys interface {
UpdateUser(data *pb.Cache_UserData) (err error)
}
)
@ -26,3 +29,7 @@ func NewSys(option ...Option) (sys ISys, err error) {
defsys, err = newSys(options)
return
}
func UpdateUser(data *pb.Cache_UserData) (err error) {
return defsys.UpdateUser(data)
}

2
sys/cache/user.go vendored
View File

@ -10,7 +10,7 @@ const ( //Redis
Redis_UserCache core.Redis_Key = "user:%d" //会话列表
)
func (this *Cache) UpdateUserCache(data *pb.Cache_UserData) (err error) {
func (this *Cache) UpdateUser(data *pb.Cache_UserData) (err error) {
return
}

35
sys/db/core.go Normal file
View File

@ -0,0 +1,35 @@
package db
import "go_dreamfactory/pb"
type (
ISys interface {
UpdateUser(data *pb.DB_UserData) (err error)
}
)
const ()
var defsys ISys
func OnInit(config map[string]interface{}, option ...Option) (err error) {
var options Options
if options, err = newOptions(config, option...); err != nil {
return
}
defsys, err = newSys(options)
return
}
func NewSys(option ...Option) (sys ISys, err error) {
var options Options
if options, err = newOptionsByOption(option...); err != nil {
return
}
defsys, err = newSys(options)
return
}
func UpdateUser(data *pb.DB_UserData) (err error) {
return defsys.UpdateUser(data)
}

24
sys/db/db.go Normal file
View File

@ -0,0 +1,24 @@
package db
import (
"github.com/liwei1dao/lego/sys/mgo"
)
func newSys(options Options) (sys *DB, err error) {
sys = &DB{options: options}
err = sys.init()
return
}
type DB struct {
options Options
mgo mgo.ISys
}
func (this *DB) init() (err error) {
this.mgo, err = mgo.NewSys(
mgo.SetMongodbUrl(this.options.MongodbUrl),
mgo.SetMongodbDatabase(this.options.MongodbDatabase),
)
return
}

38
sys/db/options.go Normal file
View File

@ -0,0 +1,38 @@
package db
import (
"errors"
"github.com/liwei1dao/lego/utils/mapstructure"
)
type Option func(*Options)
type Options struct {
MongodbUrl string
MongodbDatabase string
}
func newOptions(config map[string]interface{}, opts ...Option) (Options, error) {
options := Options{}
if config != nil {
mapstructure.Decode(config, &options)
}
for _, o := range opts {
o(&options)
}
if len(options.MongodbUrl) == 0 || len(options.MongodbDatabase) == 0 {
return options, errors.New("MongodbUrl or MongodbDatabase is null")
}
return options, nil
}
func newOptionsByOption(opts ...Option) (Options, error) {
options := Options{}
for _, o := range opts {
o(&options)
}
if len(options.MongodbUrl) == 0 || len(options.MongodbDatabase) == 0 {
return options, errors.New("MongodbUrl or MongodbDatabase is null")
}
return options, nil
}

17
sys/db/user.go Normal file
View File

@ -0,0 +1,17 @@
package db
import (
"go_dreamfactory/pb"
"github.com/liwei1dao/lego/core"
)
const ( //Redis
DB_UserTable core.SqlTable = "user" //会话列表
)
//更新用户数据到DB
func (this *DB) UpdateUser(data *pb.DB_UserData) (err error) {
return
}