feat: 修改协议(mq、push),修复问题(礼物乱窜),添加用户rpc
parent
491699a20f
commit
aa7454bba6
@ -0,0 +1,3 @@
|
||||
package pb
|
||||
|
||||
//go:generate goctl rpc protoc user_center.proto --style=go_zero --go_out=../ --go-grpc_out=../ --zrpc_out=../
|
@ -0,0 +1,344 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v3.19.4
|
||||
// source: user_center.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// model
|
||||
type User struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
||||
// platform
|
||||
Platform string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"`
|
||||
PUid string `protobuf:"bytes,4,opt,name=pUid,proto3" json:"pUid,omitempty"`
|
||||
PUname string `protobuf:"bytes,5,opt,name=pUname,proto3" json:"pUname,omitempty"`
|
||||
PAvatar string `protobuf:"bytes,6,opt,name=pAvatar,proto3" json:"pAvatar,omitempty"`
|
||||
PInfo string `protobuf:"bytes,7,opt,name=pInfo,proto3" json:"pInfo,omitempty"`
|
||||
}
|
||||
|
||||
func (x *User) Reset() {
|
||||
*x = User{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_user_center_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *User) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*User) ProtoMessage() {}
|
||||
|
||||
func (x *User) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_center_proto_msgTypes[0]
|
||||
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 User.ProtoReflect.Descriptor instead.
|
||||
func (*User) Descriptor() ([]byte, []int) {
|
||||
return file_user_center_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *User) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *User) GetUsername() string {
|
||||
if x != nil {
|
||||
return x.Username
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetPlatform() string {
|
||||
if x != nil {
|
||||
return x.Platform
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetPUid() string {
|
||||
if x != nil {
|
||||
return x.PUid
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetPUname() string {
|
||||
if x != nil {
|
||||
return x.PUname
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetPAvatar() string {
|
||||
if x != nil {
|
||||
return x.PAvatar
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetPInfo() string {
|
||||
if x != nil {
|
||||
return x.PInfo
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// req
|
||||
type PlatformUserReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"`
|
||||
PUid string `protobuf:"bytes,2,opt,name=pUid,proto3" json:"pUid,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PlatformUserReq) Reset() {
|
||||
*x = PlatformUserReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_user_center_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *PlatformUserReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*PlatformUserReq) ProtoMessage() {}
|
||||
|
||||
func (x *PlatformUserReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_center_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 PlatformUserReq.ProtoReflect.Descriptor instead.
|
||||
func (*PlatformUserReq) Descriptor() ([]byte, []int) {
|
||||
return file_user_center_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *PlatformUserReq) GetPlatform() string {
|
||||
if x != nil {
|
||||
return x.Platform
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *PlatformUserReq) GetPUid() string {
|
||||
if x != nil {
|
||||
return x.PUid
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type PlatformUserResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PlatformUserResp) Reset() {
|
||||
*x = PlatformUserResp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_user_center_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *PlatformUserResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*PlatformUserResp) ProtoMessage() {}
|
||||
|
||||
func (x *PlatformUserResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_center_proto_msgTypes[2]
|
||||
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 PlatformUserResp.ProtoReflect.Descriptor instead.
|
||||
func (*PlatformUserResp) Descriptor() ([]byte, []int) {
|
||||
return file_user_center_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *PlatformUserResp) GetUser() *User {
|
||||
if x != nil {
|
||||
return x.User
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_user_center_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_user_center_proto_rawDesc = []byte{
|
||||
0x0a, 0x11, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0xaa, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72,
|
||||
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64,
|
||||
0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08,
|
||||
0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
|
||||
0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x55, 0x69, 0x64,
|
||||
0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x55, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x70, 0x55, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x55,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18,
|
||||
0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x14,
|
||||
0x0a, 0x05, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70,
|
||||
0x49, 0x6e, 0x66, 0x6f, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d,
|
||||
0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66,
|
||||
0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66,
|
||||
0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x55, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x04, 0x70, 0x55, 0x69, 0x64, 0x22, 0x30, 0x0a, 0x10, 0x50, 0x6c, 0x61, 0x74, 0x66,
|
||||
0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1c, 0x0a, 0x04, 0x75,
|
||||
0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55,
|
||||
0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x32, 0x4f, 0x0a, 0x0a, 0x75, 0x73, 0x65,
|
||||
0x72, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x14, 0x72, 0x65, 0x74, 0x72, 0x69,
|
||||
0x65, 0x76, 0x65, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x12,
|
||||
0x13, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x55, 0x73, 0x65,
|
||||
0x72, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f,
|
||||
0x72, 0x6d, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f,
|
||||
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_user_center_proto_rawDescOnce sync.Once
|
||||
file_user_center_proto_rawDescData = file_user_center_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_user_center_proto_rawDescGZIP() []byte {
|
||||
file_user_center_proto_rawDescOnce.Do(func() {
|
||||
file_user_center_proto_rawDescData = protoimpl.X.CompressGZIP(file_user_center_proto_rawDescData)
|
||||
})
|
||||
return file_user_center_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_user_center_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_user_center_proto_goTypes = []interface{}{
|
||||
(*User)(nil), // 0: pb.User
|
||||
(*PlatformUserReq)(nil), // 1: pb.PlatformUserReq
|
||||
(*PlatformUserResp)(nil), // 2: pb.PlatformUserResp
|
||||
}
|
||||
var file_user_center_proto_depIdxs = []int32{
|
||||
0, // 0: pb.PlatformUserResp.user:type_name -> pb.User
|
||||
1, // 1: pb.userCenter.retrievePlatformUser:input_type -> pb.PlatformUserReq
|
||||
2, // 2: pb.userCenter.retrievePlatformUser:output_type -> pb.PlatformUserResp
|
||||
2, // [2:3] is the sub-list for method output_type
|
||||
1, // [1:2] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension 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_center_proto_init() }
|
||||
func file_user_center_proto_init() {
|
||||
if File_user_center_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_user_center_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*User); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_user_center_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*PlatformUserReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_user_center_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*PlatformUserResp); 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{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_user_center_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 3,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_user_center_proto_goTypes,
|
||||
DependencyIndexes: file_user_center_proto_depIdxs,
|
||||
MessageInfos: file_user_center_proto_msgTypes,
|
||||
}.Build()
|
||||
File_user_center_proto = out.File
|
||||
file_user_center_proto_rawDesc = nil
|
||||
file_user_center_proto_goTypes = nil
|
||||
file_user_center_proto_depIdxs = nil
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package pb;
|
||||
|
||||
option go_package = "./pb";
|
||||
|
||||
// model
|
||||
message User {
|
||||
int64 id = 1;
|
||||
string username = 2;
|
||||
// platform
|
||||
string platform = 3;
|
||||
string pUid = 4;
|
||||
string pUname = 5;
|
||||
string pAvatar = 6;
|
||||
string pInfo = 7;
|
||||
}
|
||||
|
||||
// req
|
||||
message PlatformUserReq {
|
||||
string platform = 1;
|
||||
string pUid = 2;
|
||||
}
|
||||
|
||||
message PlatformUserResp {
|
||||
User user = 1;
|
||||
}
|
||||
|
||||
|
||||
service userCenter {
|
||||
// user
|
||||
rpc retrievePlatformUser(PlatformUserReq) returns (PlatformUserResp);
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.19.4
|
||||
// source: user_center.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// UserCenterClient is the client API for UserCenter service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type UserCenterClient interface {
|
||||
// user
|
||||
RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error)
|
||||
}
|
||||
|
||||
type userCenterClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewUserCenterClient(cc grpc.ClientConnInterface) UserCenterClient {
|
||||
return &userCenterClient{cc}
|
||||
}
|
||||
|
||||
func (c *userCenterClient) RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error) {
|
||||
out := new(PlatformUserResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.userCenter/retrievePlatformUser", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserCenterServer is the server API for UserCenter service.
|
||||
// All implementations must embed UnimplementedUserCenterServer
|
||||
// for forward compatibility
|
||||
type UserCenterServer interface {
|
||||
// user
|
||||
RetrievePlatformUser(context.Context, *PlatformUserReq) (*PlatformUserResp, error)
|
||||
mustEmbedUnimplementedUserCenterServer()
|
||||
}
|
||||
|
||||
// UnimplementedUserCenterServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedUserCenterServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedUserCenterServer) RetrievePlatformUser(context.Context, *PlatformUserReq) (*PlatformUserResp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RetrievePlatformUser not implemented")
|
||||
}
|
||||
func (UnimplementedUserCenterServer) mustEmbedUnimplementedUserCenterServer() {}
|
||||
|
||||
// UnsafeUserCenterServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to UserCenterServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeUserCenterServer interface {
|
||||
mustEmbedUnimplementedUserCenterServer()
|
||||
}
|
||||
|
||||
func RegisterUserCenterServer(s grpc.ServiceRegistrar, srv UserCenterServer) {
|
||||
s.RegisterService(&UserCenter_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _UserCenter_RetrievePlatformUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(PlatformUserReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserCenterServer).RetrievePlatformUser(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/pb.userCenter/retrievePlatformUser",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserCenterServer).RetrievePlatformUser(ctx, req.(*PlatformUserReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// UserCenter_ServiceDesc is the grpc.ServiceDesc for UserCenter service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var UserCenter_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "pb.userCenter",
|
||||
HandlerType: (*UserCenterServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "retrievePlatformUser",
|
||||
Handler: _UserCenter_RetrievePlatformUser_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "user_center.proto",
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
// Source: user_center.proto
|
||||
|
||||
package usercenter
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"dcg/app/user_center/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
PlatformUserReq = pb.PlatformUserReq
|
||||
PlatformUserResp = pb.PlatformUserResp
|
||||
User = pb.User
|
||||
|
||||
UserCenter interface {
|
||||
// user
|
||||
RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error)
|
||||
}
|
||||
|
||||
defaultUserCenter struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewUserCenter(cli zrpc.Client) UserCenter {
|
||||
return &defaultUserCenter{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// user
|
||||
func (m *defaultUserCenter) RetrievePlatformUser(ctx context.Context, in *PlatformUserReq, opts ...grpc.CallOption) (*PlatformUserResp, error) {
|
||||
client := pb.NewUserCenterClient(m.cli.Conn())
|
||||
return client.RetrievePlatformUser(ctx, in, opts...)
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package danmaku
|
||||
|
||||
import (
|
||||
"git.noahlan.cn/northlan/ntools-go/stringn/ac"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
CMD struct {
|
||||
IsCMD bool // 是否CMD
|
||||
Arr []string // 具体CMD []string
|
||||
}
|
||||
Parser struct {
|
||||
trie *ac.Trie
|
||||
allKeyArr []string
|
||||
keywordMap map[string]struct{}
|
||||
}
|
||||
ParserBuilder struct {
|
||||
}
|
||||
)
|
||||
|
||||
func NewCMDParser(keys []string) *Parser {
|
||||
p := &Parser{
|
||||
keywordMap: make(map[string]struct{}),
|
||||
allKeyArr: make([]string, len(keys)),
|
||||
}
|
||||
for _, keyword := range keys {
|
||||
p.keywordMap[keyword] = struct{}{}
|
||||
p.allKeyArr = append(p.allKeyArr, keyword)
|
||||
}
|
||||
p.trie = ac.NewTrieBuilder().AddStrings(p.allKeyArr).Build()
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Parser) ParseTest(content string) {
|
||||
p.trie.MatchString(content)
|
||||
}
|
||||
|
||||
func (p *Parser) Parse(content string) *CMD {
|
||||
// 移除多余空格,小写
|
||||
tmpContent := strings.ToLower(strings.TrimSpace(content))
|
||||
matches := p.trie.MatchString(tmpContent)
|
||||
|
||||
allKeyLen := 0
|
||||
matchedKeyMap := make(map[string]struct{})
|
||||
for _, match := range matches {
|
||||
tmp := p.allKeyArr[match.Pattern()]
|
||||
matchedKeyMap[tmp] = struct{}{}
|
||||
allKeyLen += len(tmp)
|
||||
}
|
||||
isCMD := len(tmpContent) <= allKeyLen
|
||||
|
||||
// 避免同类型指令重复
|
||||
arrMap := make(map[rune]struct{})
|
||||
var matchedCmdArr []string
|
||||
if isCMD {
|
||||
matchedCmdArr = make([]string, 0, len(matchedKeyMap))
|
||||
for s := range matchedKeyMap {
|
||||
sRune := []rune(s)
|
||||
if _, ok := arrMap[sRune[0]]; !ok {
|
||||
arrMap[sRune[0]] = struct{}{}
|
||||
matchedCmdArr = append(matchedCmdArr, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
return &CMD{
|
||||
IsCMD: len(tmpContent) <= allKeyLen,
|
||||
Arr: matchedCmdArr,
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package danmaku
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
contents := []string{
|
||||
"jc2m2b1s",
|
||||
"jjjjjjjjjjjj",
|
||||
"c1c1c1c1c1c1c1c1c1c1",
|
||||
"c5c6c7c8c9c2c3c4c1c2c3c4c5c6c2c3c4c5c6c1",
|
||||
"j2jjjjjjjj",
|
||||
"j",
|
||||
"加入游戏",
|
||||
"加入",
|
||||
"没有什么意义的弹幕",
|
||||
"92813182798dsjks8923kjhsddfh892h3jkl214",
|
||||
"昵称为什么可以这么长",
|
||||
"六十九的覅哦我就法拉盛就发链接我i苏联空军弗拉放假 ",
|
||||
"一堆乱七八糟的弹幕来袭",
|
||||
"不服你咬我啊?",
|
||||
"红方前排速度m2b2",
|
||||
"c1c2c3c4c1c2c3c4",
|
||||
}
|
||||
|
||||
p := NewCMDParser([]string{"j", "c1", "c2", "c3", "c4", "b1", "b2", "b3", "s", "b2", "b3", "w", "m1", "m2", "m3", "加入", "加入游戏"})
|
||||
|
||||
for _, content := range contents {
|
||||
cmdStruct := p.Parse(content)
|
||||
fmt.Printf("弹幕: [%s] 是命令否? [%v]\n", content, cmdStruct.IsCMD)
|
||||
fmt.Printf("清洗后的真实命令为:%s len:%d\n\n", cmdStruct.Arr, len(cmdStruct.Arr))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCmd(b *testing.B) {
|
||||
p := NewCMDParser([]string{"j", "c1", "c2", "c3", "c4", "b1", "b2", "b3", "s", "b2", "b3", "w", "m1", "m2", "m3", "加入", "加入游戏"})
|
||||
content := "jc2m2b1s"
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
p.ParseTest(content)
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package danmaku
|
||||
|
||||
import (
|
||||
"dcg/config"
|
||||
"dcg/game/command"
|
||||
pbMq "dcg/game/pb/mq"
|
||||
pbPush "dcg/game/pb/push"
|
||||
"dcg/game/svc"
|
||||
kfk "dcg/pkg/kafka"
|
||||
"git.noahlan.cn/northlan/ntools-go/kafka"
|
||||
"git.noahlan.cn/northlan/ntools-go/logger"
|
||||
"github.com/Shopify/sarama"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type MsgToDbHandler struct {
|
||||
ctx *svc.ServiceContext
|
||||
msgHandle map[string]msgHandlerFunc
|
||||
regex *regexp.Regexp
|
||||
commandManager *command.Manager
|
||||
ConsumerGroup *kafka.ConsumerGroup
|
||||
}
|
||||
|
||||
func (h *MsgToDbHandler) Init(ctx *svc.ServiceContext) {
|
||||
h.ctx = ctx
|
||||
|
||||
cfg := config.Config.Kafka.Danmaku
|
||||
h.msgHandle = make(map[string]msgHandlerFunc)
|
||||
h.msgHandle["danmaku"] = h.handleDanmaku
|
||||
|
||||
h.commandManager = command.NewManager()
|
||||
h.commandManager.Register("j", h.handleAllCmd)
|
||||
h.commandManager.Register("c", h.handleAllCmd)
|
||||
h.commandManager.Register("s", h.handleAllCmd)
|
||||
h.commandManager.Register("m", h.handleAllCmd)
|
||||
h.commandManager.Register("w", h.handleAllCmd)
|
||||
|
||||
var err error
|
||||
h.regex, err = regexp.Compile(config.Config.Command.Regex)
|
||||
if err != nil {
|
||||
logger.SLog.Error(err)
|
||||
}
|
||||
|
||||
h.ConsumerGroup, err = kafka.NewConsumerGroup(&kafka.ConsumerGroupConfig{
|
||||
KafkaVersion: sarama.V3_1_0_0,
|
||||
OffsetsInitial: sarama.OffsetNewest,
|
||||
IsReturnErr: false,
|
||||
UnMarshaler: kfk.ProtobufMarshaler,
|
||||
}, cfg.Addr, []string{cfg.Topic}, config.Config.ConsumerGroupId.MsgToDb)
|
||||
|
||||
if err != nil {
|
||||
logger.SLog.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *MsgToDbHandler) handleAllCmd(_ int64, _ string, user *pbPush.User) {
|
||||
|
||||
}
|
||||
|
||||
func (h *MsgToDbHandler) handleDanmaku(data []byte, msgKey string) {
|
||||
// danmaku msg proto
|
||||
var msgFromMq pbMq.MqDanmaku
|
||||
err := proto.Unmarshal(data, &msgFromMq)
|
||||
if err != nil {
|
||||
logger.SLog.Error("unmarshal msg err", err)
|
||||
return
|
||||
}
|
||||
cmdArr := h.parseCommands(msgFromMq.Content)
|
||||
for _, cmd := range cmdArr {
|
||||
h.commandManager.Handle(msgFromMq.LiveRoomId, cmd, &pbPush.User{
|
||||
UId: msgFromMq.Uid,
|
||||
Uname: msgFromMq.Uname,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (h *MsgToDbHandler) parseCommands(msg string) []string {
|
||||
if h.regex == nil {
|
||||
logger.SLog.Error("regex is null")
|
||||
return []string{}
|
||||
}
|
||||
return h.regex.FindAllString(msg, -1)
|
||||
}
|
||||
|
||||
func (MsgToDbHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
|
||||
func (MsgToDbHandler) Cleanup(_ sarama.ConsumerGroupSession) error { return nil }
|
||||
func (h *MsgToDbHandler) ConsumeClaim(sess sarama.ConsumerGroupSession,
|
||||
claim sarama.ConsumerGroupClaim) error {
|
||||
for msg := range claim.Messages() {
|
||||
if hFunc, ok := h.msgHandle[msg.Topic]; ok {
|
||||
hFunc(msg.Value, string(msg.Key))
|
||||
}
|
||||
sess.MarkMessage(msg, "")
|
||||
}
|
||||
return nil
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue