fix rpc svc

This commit is contained in:
Pavel 2024-04-28 10:11:39 +03:00
parent 92620400b6
commit 3f74b1cb78
3 changed files with 97 additions and 139 deletions

@ -10,7 +10,7 @@ message Time {
}
service PromoCodeService {
rpc GetAllPromoActivations(Time) returns (PromoActivationResp);
rpc GetAllPromoActivations(Time) returns (stream PromoActivationResp);
}
message PromoActivationResp {
@ -18,9 +18,6 @@ message PromoActivationResp {
string UserID = 1;
int64 Time = 2;
}
message Activations {
repeated UserTime values = 1;
}
map<string, Activations> response = 1;
string ID = 1;
repeated UserTime Users = 2;
}

@ -80,7 +80,8 @@ type PromoActivationResp struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Response map[string]*PromoActivationResp_Activations `protobuf:"bytes,1,rep,name=response,proto3" json:"response,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
Users []*PromoActivationResp_UserTime `protobuf:"bytes,2,rep,name=Users,proto3" json:"Users,omitempty"`
}
func (x *PromoActivationResp) Reset() {
@ -115,9 +116,16 @@ func (*PromoActivationResp) Descriptor() ([]byte, []int) {
return file_promo_proto_rawDescGZIP(), []int{1}
}
func (x *PromoActivationResp) GetResponse() map[string]*PromoActivationResp_Activations {
func (x *PromoActivationResp) GetID() string {
if x != nil {
return x.Response
return x.ID
}
return ""
}
func (x *PromoActivationResp) GetUsers() []*PromoActivationResp_UserTime {
if x != nil {
return x.Users
}
return nil
}
@ -177,53 +185,6 @@ func (x *PromoActivationResp_UserTime) GetTime() int64 {
return 0
}
type PromoActivationResp_Activations struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Values []*PromoActivationResp_UserTime `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"`
}
func (x *PromoActivationResp_Activations) Reset() {
*x = PromoActivationResp_Activations{}
if protoimpl.UnsafeEnabled {
mi := &file_promo_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PromoActivationResp_Activations) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PromoActivationResp_Activations) ProtoMessage() {}
func (x *PromoActivationResp_Activations) ProtoReflect() protoreflect.Message {
mi := &file_promo_proto_msgTypes[3]
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 PromoActivationResp_Activations.ProtoReflect.Descriptor instead.
func (*PromoActivationResp_Activations) Descriptor() ([]byte, []int) {
return file_promo_proto_rawDescGZIP(), []int{1, 1}
}
func (x *PromoActivationResp_Activations) GetValues() []*PromoActivationResp_UserTime {
if x != nil {
return x.Values
}
return nil
}
var File_promo_proto protoreflect.FileDescriptor
var file_promo_proto_rawDesc = []byte{
@ -231,33 +192,22 @@ var file_promo_proto_rawDesc = []byte{
0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x2a, 0x0a, 0x04, 0x54, 0x69, 0x6d, 0x65, 0x12,
0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x66,
0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52,
0x02, 0x74, 0x6f, 0x22, 0xcd, 0x02, 0x0a, 0x13, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63, 0x74,
0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x47, 0x0a, 0x08, 0x72,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e,
0x63, 0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63,
0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x72, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x1a, 0x36, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x54, 0x69, 0x6d, 0x65,
0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x12, 0x12, 0x0a, 0x04, 0x54, 0x69, 0x6d, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x54, 0x69, 0x6d, 0x65, 0x1a, 0x4d, 0x0a, 0x0b,
0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x3e, 0x0a, 0x06, 0x76,
0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f,
0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63, 0x74, 0x69,
0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x54,
0x69, 0x6d, 0x65, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x1a, 0x66, 0x0a, 0x0d, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x3f,
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e,
0x63, 0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63,
0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x41, 0x63, 0x74,
0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
0x02, 0x38, 0x01, 0x32, 0x5b, 0x0a, 0x10, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x43, 0x6f, 0x64, 0x65,
0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x41, 0x6c,
0x6c, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x73, 0x12, 0x0e, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x54, 0x69, 0x6d,
0x65, 0x1a, 0x1d, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x50, 0x72, 0x6f,
0x6d, 0x6f, 0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70,
0x02, 0x74, 0x6f, 0x22, 0x9b, 0x01, 0x0a, 0x13, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63, 0x74,
0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x49,
0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x44, 0x12, 0x3c, 0x0a, 0x05, 0x55,
0x73, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x64,
0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63, 0x74, 0x69, 0x76,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x54, 0x69,
0x6d, 0x65, 0x52, 0x05, 0x55, 0x73, 0x65, 0x72, 0x73, 0x1a, 0x36, 0x0a, 0x08, 0x55, 0x73, 0x65,
0x72, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x12, 0x12, 0x0a,
0x04, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x54, 0x69, 0x6d,
0x65, 0x32, 0x5d, 0x0a, 0x10, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x49, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x50,
0x72, 0x6f, 0x6d, 0x6f, 0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12,
0x0e, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x1a,
0x1d, 0x2e, 0x63, 0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x2e, 0x50, 0x72, 0x6f, 0x6d, 0x6f,
0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x30, 0x01,
0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x77, 0x6f, 0x72, 0x64, 0x5f, 0x72,
0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
@ -274,25 +224,21 @@ func file_promo_proto_rawDescGZIP() []byte {
return file_promo_proto_rawDescData
}
var file_promo_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_promo_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_promo_proto_goTypes = []interface{}{
(*Time)(nil), // 0: codeword.Time
(*PromoActivationResp)(nil), // 1: codeword.PromoActivationResp
(*PromoActivationResp_UserTime)(nil), // 2: codeword.PromoActivationResp.UserTime
(*PromoActivationResp_Activations)(nil), // 3: codeword.PromoActivationResp.Activations
nil, // 4: codeword.PromoActivationResp.ResponseEntry
}
var file_promo_proto_depIdxs = []int32{
4, // 0: codeword.PromoActivationResp.response:type_name -> codeword.PromoActivationResp.ResponseEntry
2, // 1: codeword.PromoActivationResp.Activations.values:type_name -> codeword.PromoActivationResp.UserTime
3, // 2: codeword.PromoActivationResp.ResponseEntry.value:type_name -> codeword.PromoActivationResp.Activations
0, // 3: codeword.PromoCodeService.GetAllPromoActivations:input_type -> codeword.Time
1, // 4: codeword.PromoCodeService.GetAllPromoActivations:output_type -> codeword.PromoActivationResp
4, // [4:5] is the sub-list for method output_type
3, // [3:4] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
2, // 0: codeword.PromoActivationResp.Users:type_name -> codeword.PromoActivationResp.UserTime
0, // 1: codeword.PromoCodeService.GetAllPromoActivations:input_type -> codeword.Time
1, // 2: codeword.PromoCodeService.GetAllPromoActivations:output_type -> codeword.PromoActivationResp
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_promo_proto_init() }
@ -337,18 +283,6 @@ func file_promo_proto_init() {
return nil
}
}
file_promo_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PromoActivationResp_Activations); 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{
@ -356,7 +290,7 @@ func file_promo_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_promo_proto_rawDesc,
NumEnums: 0,
NumMessages: 5,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},

@ -18,7 +18,7 @@ const _ = grpc.SupportPackageIsVersion7
//
// 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 PromoCodeServiceClient interface {
GetAllPromoActivations(ctx context.Context, in *Time, opts ...grpc.CallOption) (*PromoActivationResp, error)
GetAllPromoActivations(ctx context.Context, in *Time, opts ...grpc.CallOption) (PromoCodeService_GetAllPromoActivationsClient, error)
}
type promoCodeServiceClient struct {
@ -29,20 +29,43 @@ func NewPromoCodeServiceClient(cc grpc.ClientConnInterface) PromoCodeServiceClie
return &promoCodeServiceClient{cc}
}
func (c *promoCodeServiceClient) GetAllPromoActivations(ctx context.Context, in *Time, opts ...grpc.CallOption) (*PromoActivationResp, error) {
out := new(PromoActivationResp)
err := c.cc.Invoke(ctx, "/codeword.PromoCodeService/GetAllPromoActivations", in, out, opts...)
func (c *promoCodeServiceClient) GetAllPromoActivations(ctx context.Context, in *Time, opts ...grpc.CallOption) (PromoCodeService_GetAllPromoActivationsClient, error) {
stream, err := c.cc.NewStream(ctx, &PromoCodeService_ServiceDesc.Streams[0], "/codeword.PromoCodeService/GetAllPromoActivations", opts...)
if err != nil {
return nil, err
}
return out, nil
x := &promoCodeServiceGetAllPromoActivationsClient{stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type PromoCodeService_GetAllPromoActivationsClient interface {
Recv() (*PromoActivationResp, error)
grpc.ClientStream
}
type promoCodeServiceGetAllPromoActivationsClient struct {
grpc.ClientStream
}
func (x *promoCodeServiceGetAllPromoActivationsClient) Recv() (*PromoActivationResp, error) {
m := new(PromoActivationResp)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// PromoCodeServiceServer is the server API for PromoCodeService service.
// All implementations must embed UnimplementedPromoCodeServiceServer
// for forward compatibility
type PromoCodeServiceServer interface {
GetAllPromoActivations(context.Context, *Time) (*PromoActivationResp, error)
GetAllPromoActivations(*Time, PromoCodeService_GetAllPromoActivationsServer) error
mustEmbedUnimplementedPromoCodeServiceServer()
}
@ -50,8 +73,8 @@ type PromoCodeServiceServer interface {
type UnimplementedPromoCodeServiceServer struct {
}
func (UnimplementedPromoCodeServiceServer) GetAllPromoActivations(context.Context, *Time) (*PromoActivationResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetAllPromoActivations not implemented")
func (UnimplementedPromoCodeServiceServer) GetAllPromoActivations(*Time, PromoCodeService_GetAllPromoActivationsServer) error {
return status.Errorf(codes.Unimplemented, "method GetAllPromoActivations not implemented")
}
func (UnimplementedPromoCodeServiceServer) mustEmbedUnimplementedPromoCodeServiceServer() {}
@ -66,22 +89,25 @@ func RegisterPromoCodeServiceServer(s grpc.ServiceRegistrar, srv PromoCodeServic
s.RegisterService(&PromoCodeService_ServiceDesc, srv)
}
func _PromoCodeService_GetAllPromoActivations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Time)
if err := dec(in); err != nil {
return nil, err
func _PromoCodeService_GetAllPromoActivations_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(Time)
if err := stream.RecvMsg(m); err != nil {
return err
}
if interceptor == nil {
return srv.(PromoCodeServiceServer).GetAllPromoActivations(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/codeword.PromoCodeService/GetAllPromoActivations",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PromoCodeServiceServer).GetAllPromoActivations(ctx, req.(*Time))
}
return interceptor(ctx, in, info, handler)
return srv.(PromoCodeServiceServer).GetAllPromoActivations(m, &promoCodeServiceGetAllPromoActivationsServer{stream})
}
type PromoCodeService_GetAllPromoActivationsServer interface {
Send(*PromoActivationResp) error
grpc.ServerStream
}
type promoCodeServiceGetAllPromoActivationsServer struct {
grpc.ServerStream
}
func (x *promoCodeServiceGetAllPromoActivationsServer) Send(m *PromoActivationResp) error {
return x.ServerStream.SendMsg(m)
}
// PromoCodeService_ServiceDesc is the grpc.ServiceDesc for PromoCodeService service.
@ -90,12 +116,13 @@ func _PromoCodeService_GetAllPromoActivations_Handler(srv interface{}, ctx conte
var PromoCodeService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "codeword.PromoCodeService",
HandlerType: (*PromoCodeServiceServer)(nil),
Methods: []grpc.MethodDesc{
Methods: []grpc.MethodDesc{},
Streams: []grpc.StreamDesc{
{
MethodName: "GetAllPromoActivations",
StreamName: "GetAllPromoActivations",
Handler: _PromoCodeService_GetAllPromoActivations_Handler,
ServerStreams: true,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "promo.proto",
}