拆分api文件

This commit is contained in:
liwei1dao 2022-06-09 13:36:57 +08:00
parent a837cbb62a
commit 152a8d859e
7 changed files with 158 additions and 141 deletions

30
modules/pack/api.go Normal file
View File

@ -0,0 +1,30 @@
package pack
import (
"go_dreamfactory/modules"
"go_dreamfactory/lego/core"
)
const ( //消息回复的头名称
GetlistResp = "getlistresp"
UseItemResp = "useitemresp"
SellItemResp = "sellitemresp"
)
/*
背包 处理用户的请求组件 必须继承 modules.MComp_GateComp
*/
type Api_Comp struct {
modules.MComp_GateComp
service core.IService
module *Pack
}
//组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options)
this.service = service
this.module = module.(*Pack)
return
}

View File

@ -1,89 +0,0 @@
package pack
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
)
const ( //消息回复的头名称
QueryUserPackResp = "queryuserpackresp"
UseItemResp = "useitemresp"
SellItemResp = "sellitemresp"
)
/*
背包 处理用户的请求组件 必须继承 modules.MComp_GateComp
*/
type Api_Comp struct {
modules.MComp_GateComp
service core.IService
module *Pack
}
//组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options)
this.service = service
this.module = module.(*Pack)
return
}
///查询用户背包数据
func (this *Api_Comp) QueryUserPackReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) {
var (
code pb.ErrorCode
pack *pb.DB_UserPackData
grids []*pb.DB_GridData
)
defer func() {
session.SendMsg(string(this.module.GetType()), QueryUserPackResp, code, &pb.QueryUserPackResp{Grids: grids})
}()
if !session.IsLogin() {
code = pb.ErrorCode_NoLogin
return
}
if pack, err = cache.Defsys.Pack_QueryUserPack(session.GetUserId()); err != nil {
log.Errorf("QueryUserPackReq err:%v", err)
code = pb.ErrorCode_CacheReadError
return
} else {
grids = this.module.configure_comp.GetPackItemByType(pack, req.IType)
}
return
}
//使用道具
func (this *Api_Comp) UseItemReq(ctx context.Context, session comm.IUserSession, req *pb.UseItemReq) (err error) {
var (
code pb.ErrorCode
)
defer func() {
session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{})
}()
if !session.IsLogin() {
code = pb.ErrorCode_NoLogin
return
}
return
}
//出售道具
func (this *Api_Comp) SellItemReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) {
var (
code pb.ErrorCode
)
defer func() {
session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{})
}()
if !session.IsLogin() {
code = pb.ErrorCode_NoLogin
return
}
return
}

View File

@ -0,0 +1,33 @@
package pack
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
)
///获取用户道具
func (this *Api_Comp) Getlist(ctx context.Context, session comm.IUserSession, req *pb.GetlistReq) (err error) {
var (
code pb.ErrorCode
pack *pb.DB_UserPackData
grids []*pb.DB_GridData
)
defer func() {
session.SendMsg(string(this.module.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids})
}()
if !session.IsLogin() {
code = pb.ErrorCode_NoLogin
return
}
if pack, err = cache.Defsys.Pack_QueryUserPack(session.GetUserId()); err != nil {
log.Errorf("QueryUserPackReq err:%v", err)
code = pb.ErrorCode_CacheReadError
return
} else {
grids = this.module.configure_comp.GetPackItemByType(pack, req.IType)
}
return
}

View File

@ -0,0 +1,22 @@
package pack
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
//出售道具
func (this *Api_Comp) SellItem(ctx context.Context, session comm.IUserSession, req *pb.SellItemReq) (err error) {
var (
code pb.ErrorCode
)
defer func() {
session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{})
}()
if !session.IsLogin() {
code = pb.ErrorCode_NoLogin
return
}
return
}

View File

@ -0,0 +1,22 @@
package pack
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
//使用道具
func (this *Api_Comp) Useitem(ctx context.Context, session comm.IUserSession, req *pb.UseItemReq) (err error) {
var (
code pb.ErrorCode
)
defer func() {
session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{})
}()
if !session.IsLogin() {
code = pb.ErrorCode_NoLogin
return
}
return
}

View File

@ -21,7 +21,7 @@ const (
)
//查询用户背包请求
type QueryUserPackReq struct {
type GetlistReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -29,8 +29,8 @@ type QueryUserPackReq struct {
IType int32 `protobuf:"varint,1,opt,name=IType,proto3" json:"IType,omitempty"`
}
func (x *QueryUserPackReq) Reset() {
*x = QueryUserPackReq{}
func (x *GetlistReq) Reset() {
*x = GetlistReq{}
if protoimpl.UnsafeEnabled {
mi := &file_pack_pack_msg_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -38,13 +38,13 @@ func (x *QueryUserPackReq) Reset() {
}
}
func (x *QueryUserPackReq) String() string {
func (x *GetlistReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*QueryUserPackReq) ProtoMessage() {}
func (*GetlistReq) ProtoMessage() {}
func (x *QueryUserPackReq) ProtoReflect() protoreflect.Message {
func (x *GetlistReq) ProtoReflect() protoreflect.Message {
mi := &file_pack_pack_msg_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -56,12 +56,12 @@ func (x *QueryUserPackReq) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use QueryUserPackReq.ProtoReflect.Descriptor instead.
func (*QueryUserPackReq) Descriptor() ([]byte, []int) {
// Deprecated: Use GetlistReq.ProtoReflect.Descriptor instead.
func (*GetlistReq) Descriptor() ([]byte, []int) {
return file_pack_pack_msg_proto_rawDescGZIP(), []int{0}
}
func (x *QueryUserPackReq) GetIType() int32 {
func (x *GetlistReq) GetIType() int32 {
if x != nil {
return x.IType
}
@ -69,7 +69,7 @@ func (x *QueryUserPackReq) GetIType() int32 {
}
//查询用户背包请求 回应
type QueryUserPackResp struct {
type GetlistResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -77,8 +77,8 @@ type QueryUserPackResp struct {
Grids []*DB_GridData `protobuf:"bytes,1,rep,name=Grids,proto3" json:"Grids,omitempty"`
}
func (x *QueryUserPackResp) Reset() {
*x = QueryUserPackResp{}
func (x *GetlistResp) Reset() {
*x = GetlistResp{}
if protoimpl.UnsafeEnabled {
mi := &file_pack_pack_msg_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -86,13 +86,13 @@ func (x *QueryUserPackResp) Reset() {
}
}
func (x *QueryUserPackResp) String() string {
func (x *GetlistResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*QueryUserPackResp) ProtoMessage() {}
func (*GetlistResp) ProtoMessage() {}
func (x *QueryUserPackResp) ProtoReflect() protoreflect.Message {
func (x *GetlistResp) ProtoReflect() protoreflect.Message {
mi := &file_pack_pack_msg_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -104,12 +104,12 @@ func (x *QueryUserPackResp) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use QueryUserPackResp.ProtoReflect.Descriptor instead.
func (*QueryUserPackResp) Descriptor() ([]byte, []int) {
// Deprecated: Use GetlistResp.ProtoReflect.Descriptor instead.
func (*GetlistResp) Descriptor() ([]byte, []int) {
return file_pack_pack_msg_proto_rawDescGZIP(), []int{1}
}
func (x *QueryUserPackResp) GetGrids() []*DB_GridData {
func (x *GetlistResp) GetGrids() []*DB_GridData {
if x != nil {
return x.Grids
}
@ -327,27 +327,26 @@ var File_pack_pack_msg_proto protoreflect.FileDescriptor
var file_pack_pack_msg_proto_rawDesc = []byte{
0x0a, 0x13, 0x70, 0x61, 0x63, 0x6b, 0x2f, 0x70, 0x61, 0x63, 0x6b, 0x5f, 0x6d, 0x73, 0x67, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x12, 0x70, 0x61, 0x63, 0x6b, 0x2f, 0x70, 0x61, 0x63, 0x6b,
0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x28, 0x0a, 0x10, 0x51, 0x75, 0x65,
0x72, 0x79, 0x55, 0x73, 0x65, 0x72, 0x50, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a,
0x05, 0x49, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x49, 0x54,
0x79, 0x70, 0x65, 0x22, 0x37, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x55, 0x73, 0x65, 0x72,
0x50, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x22, 0x0a, 0x05, 0x47, 0x72, 0x69, 0x64,
0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x5f, 0x47, 0x72, 0x69,
0x64, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x47, 0x72, 0x69, 0x64, 0x73, 0x22, 0x54, 0x0a, 0x0a,
0x55, 0x73, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72,
0x69, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x47, 0x72, 0x69, 0x64,
0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x05, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d,
0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75,
0x6e, 0x74, 0x22, 0x0d, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x73,
0x70, 0x22, 0x55, 0x0a, 0x0b, 0x53, 0x65, 0x6c, 0x6c, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x71,
0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d,
0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64,
0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x0e, 0x0a, 0x0c, 0x53, 0x65, 0x6c, 0x6c,
0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x22, 0x0a, 0x0a, 0x47, 0x65, 0x74,
0x6c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x49, 0x54, 0x79, 0x70, 0x65,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x49, 0x54, 0x79, 0x70, 0x65, 0x22, 0x31, 0x0a,
0x0b, 0x47, 0x65, 0x74, 0x6c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x22, 0x0a, 0x05,
0x47, 0x72, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42,
0x5f, 0x47, 0x72, 0x69, 0x64, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x47, 0x72, 0x69, 0x64, 0x73,
0x22, 0x54, 0x0a, 0x0a, 0x55, 0x73, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x71, 0x12, 0x16,
0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64,
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x16,
0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06,
0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x0d, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x49, 0x74, 0x65,
0x6d, 0x52, 0x65, 0x73, 0x70, 0x22, 0x55, 0x0a, 0x0b, 0x53, 0x65, 0x6c, 0x6c, 0x49, 0x74, 0x65,
0x6d, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06,
0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, 0x74,
0x65, 0x6d, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03,
0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x0e, 0x0a, 0x0c,
0x53, 0x65, 0x6c, 0x6c, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04,
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -364,16 +363,16 @@ func file_pack_pack_msg_proto_rawDescGZIP() []byte {
var file_pack_pack_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_pack_pack_msg_proto_goTypes = []interface{}{
(*QueryUserPackReq)(nil), // 0: QueryUserPackReq
(*QueryUserPackResp)(nil), // 1: QueryUserPackResp
(*UseItemReq)(nil), // 2: UseItemReq
(*UseItemResp)(nil), // 3: UseItemResp
(*SellItemReq)(nil), // 4: SellItemReq
(*SellItemResp)(nil), // 5: SellItemResp
(*DB_GridData)(nil), // 6: DB_GridData
(*GetlistReq)(nil), // 0: GetlistReq
(*GetlistResp)(nil), // 1: GetlistResp
(*UseItemReq)(nil), // 2: UseItemReq
(*UseItemResp)(nil), // 3: UseItemResp
(*SellItemReq)(nil), // 4: SellItemReq
(*SellItemResp)(nil), // 5: SellItemResp
(*DB_GridData)(nil), // 6: DB_GridData
}
var file_pack_pack_msg_proto_depIdxs = []int32{
6, // 0: QueryUserPackResp.Grids:type_name -> DB_GridData
6, // 0: GetlistResp.Grids:type_name -> DB_GridData
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
@ -389,7 +388,7 @@ func file_pack_pack_msg_proto_init() {
file_pack_pack_db_proto_init()
if !protoimpl.UnsafeEnabled {
file_pack_pack_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*QueryUserPackReq); i {
switch v := v.(*GetlistReq); i {
case 0:
return &v.state
case 1:
@ -401,7 +400,7 @@ func file_pack_pack_msg_proto_init() {
}
}
file_pack_pack_msg_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*QueryUserPackResp); i {
switch v := v.(*GetlistResp); i {
case 0:
return &v.state
case 1:

View File

@ -3,12 +3,12 @@ option go_package = ".;pb";
import "pack/pack_db.proto";
//
message QueryUserPackReq {
message GetlistReq {
int32 IType = 1;
}
//
message QueryUserPackResp {
message GetlistResp {
repeated DB_GridData Grids = 1;
}
@ -24,7 +24,7 @@ message UseItemResp {
}
//
//sailitem
message SellItemReq {
int32 GridId = 1; //Id
int32 ItemId = 2; //Id