db测试
This commit is contained in:
parent
e9fc2df0a3
commit
277739e2b7
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,7 +12,7 @@
|
|||||||
*.log
|
*.log
|
||||||
bin/conf
|
bin/conf
|
||||||
|
|
||||||
.vscode
|
.vscode/
|
||||||
./bin/conf
|
./bin/conf
|
||||||
./bin/log
|
./bin/log
|
||||||
~$*.xlsx
|
~$*.xlsx
|
||||||
|
@ -12,8 +12,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SM_GateModule core.M_Modules = "SM_GateModule" //gate模块 网关服务模块
|
SM_GateModule core.M_Modules = "SM_GateModule" //gate模块 网关服务模块
|
||||||
SM_WebModule core.M_Modules = "SM_WebModule" //web模块
|
SM_WebModule core.M_Modules = "SM_WebModule" //web模块
|
||||||
|
SM_LoginModule core.M_Modules = "SM_LoginModule" //web模块
|
||||||
)
|
)
|
||||||
|
|
||||||
const ( //Rpc
|
const ( //Rpc
|
||||||
|
4
go.mod
4
go.mod
@ -5,6 +5,7 @@ go 1.18
|
|||||||
require (
|
require (
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/liwei1dao/lego v0.0.0-20220531091126-a21bb3766fbc
|
github.com/liwei1dao/lego v0.0.0-20220531091126-a21bb3766fbc
|
||||||
|
github.com/stretchr/testify v1.7.1
|
||||||
google.golang.org/protobuf v1.28.0
|
google.golang.org/protobuf v1.28.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ require (
|
|||||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
github.com/cheekybits/genny v1.0.0 // indirect
|
github.com/cheekybits/genny v1.0.0 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/dgryski/go-jump v0.0.0-20211018200510-ba001c3ffce0 // indirect
|
github.com/dgryski/go-jump v0.0.0-20211018200510-ba001c3ffce0 // 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/edwingeng/doublejump v0.0.0-20210724020454-c82f1bcb3280 // indirect
|
github.com/edwingeng/doublejump v0.0.0-20210724020454-c82f1bcb3280 // indirect
|
||||||
@ -78,6 +80,7 @@ require (
|
|||||||
github.com/onsi/ginkgo v1.16.5 // indirect
|
github.com/onsi/ginkgo v1.16.5 // indirect
|
||||||
github.com/philhofer/fwd v1.1.1 // indirect
|
github.com/philhofer/fwd v1.1.1 // 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/robfig/cron/v3 v3.0.1 // indirect
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
github.com/rpcxio/libkv v0.5.1-0.20210420120011-1fceaedca8a5 // indirect
|
github.com/rpcxio/libkv v0.5.1-0.20210420120011-1fceaedca8a5 // indirect
|
||||||
github.com/rs/cors v1.8.2 // indirect
|
github.com/rs/cors v1.8.2 // indirect
|
||||||
@ -120,6 +123,7 @@ require (
|
|||||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
// replace github.com/liwei1dao/lego => F:\work\go\lego
|
// replace github.com/liwei1dao/lego => F:\work\go\lego
|
||||||
|
27
modules/login/login_comp.go
Normal file
27
modules/login/login_comp.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package login
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/modules"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"github.com/liwei1dao/lego/sys/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoginComp struct {
|
||||||
|
modules.MComp_GateComp
|
||||||
|
}
|
||||||
|
|
||||||
|
//登录
|
||||||
|
func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, rsp *pb.UserLoginReq) error {
|
||||||
|
log.Debugf("User - Login: session:%v rsp:%v", session.ToString(), rsp)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *LoginComp) Logout(ctx context.Context, session comm.IUserSession, rsp *pb.UserLoginReq) error {
|
||||||
|
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
27
modules/login/module.go
Normal file
27
modules/login/module.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package login
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/modules"
|
||||||
|
|
||||||
|
"github.com/liwei1dao/lego/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewModule() core.IModule {
|
||||||
|
m := new(Login)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
type Login struct {
|
||||||
|
modules.ModuleBase
|
||||||
|
user_comp *LoginComp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Login) GetType() core.M_Modules {
|
||||||
|
return comm.SM_LoginModule
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Login) OnInstallComp() {
|
||||||
|
this.ModuleBase.OnInstallComp()
|
||||||
|
this.user_comp = this.RegisterComp(new(LoginComp)).(*LoginComp)
|
||||||
|
}
|
@ -2,17 +2,15 @@ syntax = "proto3";
|
|||||||
option go_package = ".;pb";
|
option go_package = ".;pb";
|
||||||
|
|
||||||
message Cache_UserData {
|
message Cache_UserData {
|
||||||
uint32 UserId = 1;
|
|
||||||
string SessionId = 2;
|
string SessionId = 2;
|
||||||
string GatewayServiceId = 3;
|
string GatewayServiceId = 3;
|
||||||
string NiceName = 4;
|
DB_UserData UserData = 4;
|
||||||
string Email = 5;
|
|
||||||
string Password = 6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message DB_UserData {
|
message DB_UserData {
|
||||||
uint32 UserId = 1; //tags:{bson:"_id"}动态Id
|
uint32 UserId = 1; //tags:{bson:"_id"}动态Id
|
||||||
string NiceName = 2;
|
string account = 2;
|
||||||
string Email = 3;
|
string NiceName = 3;
|
||||||
string Password = 4;
|
string Email = 4;
|
||||||
|
string Password = 5;
|
||||||
}
|
}
|
101
pb/user_db.pb.go
101
pb/user_db.pb.go
@ -25,12 +25,9 @@ type Cache_UserData struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
UserId uint32 `protobuf:"varint,1,opt,name=UserId,proto3" json:"UserId,omitempty"`
|
SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId,omitempty"`
|
||||||
SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId,omitempty"`
|
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"`
|
||||||
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"`
|
UserData *DB_UserData `protobuf:"bytes,4,opt,name=UserData,proto3" json:"UserData,omitempty"`
|
||||||
NiceName string `protobuf:"bytes,4,opt,name=NiceName,proto3" json:"NiceName,omitempty"`
|
|
||||||
Email string `protobuf:"bytes,5,opt,name=Email,proto3" json:"Email,omitempty"`
|
|
||||||
Password string `protobuf:"bytes,6,opt,name=Password,proto3" json:"Password,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Cache_UserData) Reset() {
|
func (x *Cache_UserData) Reset() {
|
||||||
@ -65,13 +62,6 @@ func (*Cache_UserData) Descriptor() ([]byte, []int) {
|
|||||||
return file_user_db_proto_rawDescGZIP(), []int{0}
|
return file_user_db_proto_rawDescGZIP(), []int{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Cache_UserData) GetUserId() uint32 {
|
|
||||||
if x != nil {
|
|
||||||
return x.UserId
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Cache_UserData) GetSessionId() string {
|
func (x *Cache_UserData) GetSessionId() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.SessionId
|
return x.SessionId
|
||||||
@ -86,25 +76,11 @@ func (x *Cache_UserData) GetGatewayServiceId() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Cache_UserData) GetNiceName() string {
|
func (x *Cache_UserData) GetUserData() *DB_UserData {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.NiceName
|
return x.UserData
|
||||||
}
|
}
|
||||||
return ""
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Cache_UserData) GetEmail() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Email
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Cache_UserData) GetPassword() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Password
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DB_UserData struct {
|
type DB_UserData struct {
|
||||||
@ -113,9 +89,10 @@ type DB_UserData struct {
|
|||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
UserId uint32 `protobuf:"varint,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}动态Id
|
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"`
|
Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
|
||||||
Email string `protobuf:"bytes,3,opt,name=Email,proto3" json:"Email,omitempty"`
|
NiceName string `protobuf:"bytes,3,opt,name=NiceName,proto3" json:"NiceName,omitempty"`
|
||||||
Password string `protobuf:"bytes,4,opt,name=Password,proto3" json:"Password,omitempty"`
|
Email string `protobuf:"bytes,4,opt,name=Email,proto3" json:"Email,omitempty"`
|
||||||
|
Password string `protobuf:"bytes,5,opt,name=Password,proto3" json:"Password,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DB_UserData) Reset() {
|
func (x *DB_UserData) Reset() {
|
||||||
@ -157,6 +134,13 @@ func (x *DB_UserData) GetUserId() uint32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *DB_UserData) GetAccount() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Account
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (x *DB_UserData) GetNiceName() string {
|
func (x *DB_UserData) GetNiceName() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.NiceName
|
return x.NiceName
|
||||||
@ -182,27 +166,25 @@ var File_user_db_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
var file_user_db_proto_rawDesc = []byte{
|
var file_user_db_proto_rawDesc = []byte{
|
||||||
0x0a, 0x0d, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
|
0x0a, 0x0d, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
|
||||||
0xc0, 0x01, 0x0a, 0x0e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61,
|
0x84, 0x01, 0x0a, 0x0e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61,
|
||||||
0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
|
0x74, 0x61, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18,
|
||||||
0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65,
|
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64,
|
||||||
0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x53,
|
0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69,
|
||||||
0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65,
|
0x63, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65,
|
||||||
0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01,
|
0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x08,
|
||||||
0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69,
|
0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c,
|
||||||
0x63, 0x65, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65,
|
0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x08, 0x55, 0x73,
|
||||||
0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65,
|
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0x8d, 0x01, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x55, 0x73,
|
||||||
0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64,
|
||||||
0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18,
|
||||||
0x72, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f,
|
0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x72, 0x64, 0x22, 0x73, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74,
|
0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x65,
|
||||||
0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x65,
|
||||||
0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63,
|
0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x04, 0x20,
|
||||||
0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63,
|
0x01, 0x28, 0x09, 0x52, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x61,
|
||||||
0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03,
|
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50, 0x61,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x50,
|
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
|
||||||
0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50,
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
|
|
||||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -223,11 +205,12 @@ var file_user_db_proto_goTypes = []interface{}{
|
|||||||
(*DB_UserData)(nil), // 1: DB_UserData
|
(*DB_UserData)(nil), // 1: DB_UserData
|
||||||
}
|
}
|
||||||
var file_user_db_proto_depIdxs = []int32{
|
var file_user_db_proto_depIdxs = []int32{
|
||||||
0, // [0:0] is the sub-list for method output_type
|
1, // 0: Cache_UserData.UserData:type_name -> DB_UserData
|
||||||
0, // [0:0] is the sub-list for method input_type
|
1, // [1:1] is the sub-list for method output_type
|
||||||
0, // [0:0] is the sub-list for extension type_name
|
1, // [1:1] is the sub-list for method input_type
|
||||||
0, // [0:0] is the sub-list for extension extendee
|
1, // [1:1] is the sub-list for extension type_name
|
||||||
0, // [0:0] is the sub-list for field type_name
|
1, // [1:1] is the sub-list for extension extendee
|
||||||
|
0, // [0:1] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_user_db_proto_init() }
|
func init() { file_user_db_proto_init() }
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
@echo off
|
|
||||||
|
|
||||||
set PROJECT_ROOT=E:/projects/workspace/go_dreamfactory
|
|
||||||
|
|
||||||
set SRC_CLIENT=%PROJECT_ROOT%\proto\client
|
|
||||||
set TAR_CLIENT=%PROJECT_ROOT%\pb\client
|
|
||||||
|
|
||||||
set SRC_SERVER=%PROJECT_ROOT%\proto\server
|
|
||||||
set TAR_SERVER=%PROJECT_ROOT%\pb\server
|
|
||||||
|
|
||||||
::protoc -I %SRC_CLIENT% --go_out=%TAR_CLIENT% %SRC_CLIENT%/*.proto
|
|
||||||
protoc --proto_path=%SRC_CLIENT% --go_out=%TAR_CLIENT% --go_opt=paths=source_relative %SRC_CLIENT%\*.proto
|
|
||||||
|
|
||||||
protoc --proto_path=%SRC_SERVER% --go_out=%TAR_SERVER% --go_opt=paths=source_relative %SRC_SERVER%\*.proto
|
|
||||||
|
|
||||||
pause
|
|
@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"go_dreamfactory/modules/web"
|
"go_dreamfactory/modules/login"
|
||||||
"go_dreamfactory/services"
|
"go_dreamfactory/services"
|
||||||
|
|
||||||
"github.com/liwei1dao/lego"
|
"github.com/liwei1dao/lego"
|
||||||
@ -24,7 +24,8 @@ func main() {
|
|||||||
services.NewGateRouteComp(),
|
services.NewGateRouteComp(),
|
||||||
)
|
)
|
||||||
lego.Run(s, //运行模块
|
lego.Run(s, //运行模块
|
||||||
web.NewModule(),
|
// web.NewModule(),
|
||||||
|
login.NewModule(),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2
sys/cache/user.go
vendored
2
sys/cache/user.go
vendored
@ -11,6 +11,6 @@ const ( //Redis
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (this *Cache) UpdateUser(data *pb.Cache_UserData) (err error) {
|
func (this *Cache) UpdateUser(data *pb.Cache_UserData) (err error) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
19
sys/cache/user_test.go
vendored
Normal file
19
sys/cache/user_test.go
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/liwei1dao/lego/sys/redis"
|
||||||
|
)
|
||||||
|
|
||||||
|
var rds redis.IRedis
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
redis.NewSys(redis.Redis_Cluster_Addr([]string{"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.SetRedis_Cluster_Password(""))
|
||||||
|
defer m.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSet(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
@ -4,12 +4,38 @@ import (
|
|||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
"github.com/liwei1dao/lego/core"
|
"github.com/liwei1dao/lego/core"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ( //Redis
|
const ( //Redis
|
||||||
DB_UserTable core.SqlTable = "user" //会话列表
|
DB_UserTable core.SqlTable = "user" //会话列表
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (this *DB) FindUserByAccount(account string) (*pb.DB_UserData, error) {
|
||||||
|
filter := bson.D{
|
||||||
|
{"account", account},
|
||||||
|
}
|
||||||
|
sr := this.mgo.FindOne(DB_UserTable, filter)
|
||||||
|
user := &pb.DB_UserData{}
|
||||||
|
err := sr.Decode(user)
|
||||||
|
return user, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DB) FindUserById(id int) (*pb.DB_UserData, error) {
|
||||||
|
filter := bson.D{
|
||||||
|
{"_id", id},
|
||||||
|
}
|
||||||
|
sr := this.mgo.FindOne(DB_UserTable, filter)
|
||||||
|
user := &pb.DB_UserData{}
|
||||||
|
err := sr.Decode(user)
|
||||||
|
return user, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DB) CreateUser(user *pb.DB_UserData) error {
|
||||||
|
_, err := this.mgo.InsertOne(DB_UserTable, user)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
//更新用户数据到DB
|
//更新用户数据到DB
|
||||||
func (this *DB) UpdateUser(data *pb.DB_UserData) (err error) {
|
func (this *DB) UpdateUser(data *pb.DB_UserData) (err error) {
|
||||||
|
|
||||||
|
49
sys/db/user_test.go
Normal file
49
sys/db/user_test.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/liwei1dao/lego/sys/mgo"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
var db *DB
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
imgo, err := mgo.NewSys(mgo.SetMongodbUrl("mongodb://admin:123456@10.0.0.9:27018"), mgo.SetMongodbDatabase("dreamfactory"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
db = &DB{
|
||||||
|
mgo: imgo,
|
||||||
|
}
|
||||||
|
defer os.Exit(m.Run())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreate(t *testing.T) {
|
||||||
|
user := &pb.DB_UserData{
|
||||||
|
UserId: 1,
|
||||||
|
Account: "legu1",
|
||||||
|
NiceName: "乐谷1",
|
||||||
|
Email: "1111@legu.com",
|
||||||
|
}
|
||||||
|
|
||||||
|
err := db.CreateUser(user)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindOne(t *testing.T) {
|
||||||
|
user, err := db.FindUserById(1)
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.Equal(t, "legu1", user.Account)
|
||||||
|
|
||||||
|
user2, err := db.FindUserByAccount("legu1")
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.Equal(t, "legu1", user2.Account)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user