This commit is contained in:
2022-03-17 15:55:27 +08:00
commit bd5a9fad97
92 changed files with 13861 additions and 0 deletions

6
api/logic/grpc/create.sh Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
protoc -I. -I$GOPATH/src \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
*.proto

1312
api/logic/grpc/logic.pb.go Normal file

File diff suppressed because it is too large Load Diff

117
api/logic/grpc/logic.proto Normal file
View File

@@ -0,0 +1,117 @@
// protoc -I=. -I=$GOPATH/src --go_out=plugins=grpc:. *.proto
syntax = "proto3";
package im.logic;
option go_package = "gitlab.33.cn/chat/im/api/logic/grpc";
import "gitlab.33.cn/chat/im/api/comet/grpc/comet.proto";
enum Type {
PUSH = 0;
ROOM = 1;
BROADCAST = 2;
}
message ConnectReq {
string server = 1; // 客户端连接的是哪个 comet
im.comet.Proto proto = 3;
}
message ConnectReply {
string key = 1;
string appId = 2;
string mid = 3;
int64 heartbeat = 4;
}
message DisconnectReq {
string key = 1;
string server = 2;
}
message HeartbeatReq {
string key = 1;
string server = 2;
}
message ReceiveReq {
string key = 1;
im.comet.Proto proto = 3;
}
message Reply {
bool isOk = 1;
bytes msg = 2;
}
// logic --> mq
message BizMsg {
string appId = 1;
string fromId = 2;
Type type = 4;
int32 op = 5;
string key = 6;
bytes msg = 7;
}
// biz --> logic
message MidsMsg {
string appId = 1;
repeated string toIds = 2;
Type type = 3;
int32 op = 4;
bytes msg = 5;
}
// biz --> logic
message KeysMsg {
string appId = 1;
repeated string toKeys = 2;
Type type = 3;
int32 op = 4;
bytes msg = 5;
}
// biz --> logic
message GroupMsg {
string appId = 1;
string group = 2;
Type type = 3;
int32 op = 4;
bytes msg = 5;
}
// biz --> logic
message GroupsKey {
string appId = 1;
repeated string keys = 2;
repeated string gid = 3;
}
// biz --> logic
message GroupsMid {
string appId = 1;
repeated string mids = 2;
repeated string gid = 3;
}
// biz --> logic
message DelGroupsReq {
string appId = 1;
repeated string gid = 2;
}
service Logic {
rpc Connect(ConnectReq) returns (ConnectReply); //comet
rpc Disconnect(DisconnectReq) returns (Reply); //comet
rpc Heartbeat(HeartbeatReq) returns (Reply); //comet
rpc Receive(ReceiveReq) returns (Reply); //comet
rpc PushByMids(MidsMsg) returns (Reply); //biz
rpc PushByKeys(KeysMsg) returns (Reply); //biz
rpc PushGroup(GroupMsg) returns (Reply); //biz
rpc JoinGroupsByKeys(GroupsKey) returns (Reply); //biz
rpc JoinGroupsByMids(GroupsMid) returns (Reply); //biz
rpc LeaveGroupsByKeys(GroupsKey) returns (Reply); //biz
rpc LeaveGroupsByMids(GroupsMid) returns (Reply); //biz
rpc DelGroups(DelGroupsReq) returns (Reply); //biz
}

View File

@@ -0,0 +1,497 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package grpc
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
// LogicClient is the client API for Logic 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 LogicClient interface {
Connect(ctx context.Context, in *ConnectReq, opts ...grpc.CallOption) (*ConnectReply, error)
Disconnect(ctx context.Context, in *DisconnectReq, opts ...grpc.CallOption) (*Reply, error)
Heartbeat(ctx context.Context, in *HeartbeatReq, opts ...grpc.CallOption) (*Reply, error)
Receive(ctx context.Context, in *ReceiveReq, opts ...grpc.CallOption) (*Reply, error)
PushByMids(ctx context.Context, in *MidsMsg, opts ...grpc.CallOption) (*Reply, error)
PushByKeys(ctx context.Context, in *KeysMsg, opts ...grpc.CallOption) (*Reply, error)
PushGroup(ctx context.Context, in *GroupMsg, opts ...grpc.CallOption) (*Reply, error)
JoinGroupsByKeys(ctx context.Context, in *GroupsKey, opts ...grpc.CallOption) (*Reply, error)
JoinGroupsByMids(ctx context.Context, in *GroupsMid, opts ...grpc.CallOption) (*Reply, error)
LeaveGroupsByKeys(ctx context.Context, in *GroupsKey, opts ...grpc.CallOption) (*Reply, error)
LeaveGroupsByMids(ctx context.Context, in *GroupsMid, opts ...grpc.CallOption) (*Reply, error)
DelGroups(ctx context.Context, in *DelGroupsReq, opts ...grpc.CallOption) (*Reply, error)
}
type logicClient struct {
cc grpc.ClientConnInterface
}
func NewLogicClient(cc grpc.ClientConnInterface) LogicClient {
return &logicClient{cc}
}
func (c *logicClient) Connect(ctx context.Context, in *ConnectReq, opts ...grpc.CallOption) (*ConnectReply, error) {
out := new(ConnectReply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/Connect", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) Disconnect(ctx context.Context, in *DisconnectReq, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/Disconnect", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) Heartbeat(ctx context.Context, in *HeartbeatReq, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/Heartbeat", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) Receive(ctx context.Context, in *ReceiveReq, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/Receive", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) PushByMids(ctx context.Context, in *MidsMsg, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/PushByMids", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) PushByKeys(ctx context.Context, in *KeysMsg, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/PushByKeys", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) PushGroup(ctx context.Context, in *GroupMsg, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/PushGroup", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) JoinGroupsByKeys(ctx context.Context, in *GroupsKey, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/JoinGroupsByKeys", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) JoinGroupsByMids(ctx context.Context, in *GroupsMid, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/JoinGroupsByMids", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) LeaveGroupsByKeys(ctx context.Context, in *GroupsKey, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/LeaveGroupsByKeys", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) LeaveGroupsByMids(ctx context.Context, in *GroupsMid, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/LeaveGroupsByMids", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *logicClient) DelGroups(ctx context.Context, in *DelGroupsReq, opts ...grpc.CallOption) (*Reply, error) {
out := new(Reply)
err := c.cc.Invoke(ctx, "/im.logic.Logic/DelGroups", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// LogicServer is the server API for Logic service.
// All implementations must embed UnimplementedLogicServer
// for forward compatibility
type LogicServer interface {
Connect(context.Context, *ConnectReq) (*ConnectReply, error)
Disconnect(context.Context, *DisconnectReq) (*Reply, error)
Heartbeat(context.Context, *HeartbeatReq) (*Reply, error)
Receive(context.Context, *ReceiveReq) (*Reply, error)
PushByMids(context.Context, *MidsMsg) (*Reply, error)
PushByKeys(context.Context, *KeysMsg) (*Reply, error)
PushGroup(context.Context, *GroupMsg) (*Reply, error)
JoinGroupsByKeys(context.Context, *GroupsKey) (*Reply, error)
JoinGroupsByMids(context.Context, *GroupsMid) (*Reply, error)
LeaveGroupsByKeys(context.Context, *GroupsKey) (*Reply, error)
LeaveGroupsByMids(context.Context, *GroupsMid) (*Reply, error)
DelGroups(context.Context, *DelGroupsReq) (*Reply, error)
mustEmbedUnimplementedLogicServer()
}
// UnimplementedLogicServer must be embedded to have forward compatible implementations.
type UnimplementedLogicServer struct {
}
func (UnimplementedLogicServer) Connect(context.Context, *ConnectReq) (*ConnectReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Connect not implemented")
}
func (UnimplementedLogicServer) Disconnect(context.Context, *DisconnectReq) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Disconnect not implemented")
}
func (UnimplementedLogicServer) Heartbeat(context.Context, *HeartbeatReq) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Heartbeat not implemented")
}
func (UnimplementedLogicServer) Receive(context.Context, *ReceiveReq) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Receive not implemented")
}
func (UnimplementedLogicServer) PushByMids(context.Context, *MidsMsg) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method PushByMids not implemented")
}
func (UnimplementedLogicServer) PushByKeys(context.Context, *KeysMsg) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method PushByKeys not implemented")
}
func (UnimplementedLogicServer) PushGroup(context.Context, *GroupMsg) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method PushGroup not implemented")
}
func (UnimplementedLogicServer) JoinGroupsByKeys(context.Context, *GroupsKey) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method JoinGroupsByKeys not implemented")
}
func (UnimplementedLogicServer) JoinGroupsByMids(context.Context, *GroupsMid) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method JoinGroupsByMids not implemented")
}
func (UnimplementedLogicServer) LeaveGroupsByKeys(context.Context, *GroupsKey) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method LeaveGroupsByKeys not implemented")
}
func (UnimplementedLogicServer) LeaveGroupsByMids(context.Context, *GroupsMid) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method LeaveGroupsByMids not implemented")
}
func (UnimplementedLogicServer) DelGroups(context.Context, *DelGroupsReq) (*Reply, error) {
return nil, status.Errorf(codes.Unimplemented, "method DelGroups not implemented")
}
func (UnimplementedLogicServer) mustEmbedUnimplementedLogicServer() {}
// UnsafeLogicServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to LogicServer will
// result in compilation errors.
type UnsafeLogicServer interface {
mustEmbedUnimplementedLogicServer()
}
func RegisterLogicServer(s grpc.ServiceRegistrar, srv LogicServer) {
s.RegisterService(&Logic_ServiceDesc, srv)
}
func _Logic_Connect_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ConnectReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).Connect(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/Connect",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).Connect(ctx, req.(*ConnectReq))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_Disconnect_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DisconnectReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).Disconnect(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/Disconnect",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).Disconnect(ctx, req.(*DisconnectReq))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_Heartbeat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HeartbeatReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).Heartbeat(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/Heartbeat",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).Heartbeat(ctx, req.(*HeartbeatReq))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_Receive_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReceiveReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).Receive(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/Receive",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).Receive(ctx, req.(*ReceiveReq))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_PushByMids_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(MidsMsg)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).PushByMids(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/PushByMids",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).PushByMids(ctx, req.(*MidsMsg))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_PushByKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(KeysMsg)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).PushByKeys(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/PushByKeys",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).PushByKeys(ctx, req.(*KeysMsg))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_PushGroup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GroupMsg)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).PushGroup(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/PushGroup",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).PushGroup(ctx, req.(*GroupMsg))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_JoinGroupsByKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GroupsKey)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).JoinGroupsByKeys(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/JoinGroupsByKeys",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).JoinGroupsByKeys(ctx, req.(*GroupsKey))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_JoinGroupsByMids_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GroupsMid)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).JoinGroupsByMids(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/JoinGroupsByMids",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).JoinGroupsByMids(ctx, req.(*GroupsMid))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_LeaveGroupsByKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GroupsKey)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).LeaveGroupsByKeys(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/LeaveGroupsByKeys",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).LeaveGroupsByKeys(ctx, req.(*GroupsKey))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_LeaveGroupsByMids_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GroupsMid)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).LeaveGroupsByMids(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/LeaveGroupsByMids",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).LeaveGroupsByMids(ctx, req.(*GroupsMid))
}
return interceptor(ctx, in, info, handler)
}
func _Logic_DelGroups_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DelGroupsReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LogicServer).DelGroups(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/im.logic.Logic/DelGroups",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LogicServer).DelGroups(ctx, req.(*DelGroupsReq))
}
return interceptor(ctx, in, info, handler)
}
// Logic_ServiceDesc is the grpc.ServiceDesc for Logic service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Logic_ServiceDesc = grpc.ServiceDesc{
ServiceName: "im.logic.Logic",
HandlerType: (*LogicServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Connect",
Handler: _Logic_Connect_Handler,
},
{
MethodName: "Disconnect",
Handler: _Logic_Disconnect_Handler,
},
{
MethodName: "Heartbeat",
Handler: _Logic_Heartbeat_Handler,
},
{
MethodName: "Receive",
Handler: _Logic_Receive_Handler,
},
{
MethodName: "PushByMids",
Handler: _Logic_PushByMids_Handler,
},
{
MethodName: "PushByKeys",
Handler: _Logic_PushByKeys_Handler,
},
{
MethodName: "PushGroup",
Handler: _Logic_PushGroup_Handler,
},
{
MethodName: "JoinGroupsByKeys",
Handler: _Logic_JoinGroupsByKeys_Handler,
},
{
MethodName: "JoinGroupsByMids",
Handler: _Logic_JoinGroupsByMids_Handler,
},
{
MethodName: "LeaveGroupsByKeys",
Handler: _Logic_LeaveGroupsByKeys_Handler,
},
{
MethodName: "LeaveGroupsByMids",
Handler: _Logic_LeaveGroupsByMids_Handler,
},
{
MethodName: "DelGroups",
Handler: _Logic_DelGroups_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "logic.proto",
}