From 59d44ef75ebaceb63194223fa9abd4463f3d5534 Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Wed, 27 Nov 2024 19:06:34 +0100 Subject: [PATCH] Update gRPC endpoint --- pkg/grpc/grpc.go | 9 ++- pkg/grpc/quickpizza/quickpizza.pb.go | 92 +++++++++++------------ pkg/grpc/quickpizza/quickpizza_grpc.pb.go | 32 ++++---- proto/quickpizza.proto | 6 +- 4 files changed, 70 insertions(+), 69 deletions(-) diff --git a/pkg/grpc/grpc.go b/pkg/grpc/grpc.go index 1f4c4ef1..5c8712c1 100644 --- a/pkg/grpc/grpc.go +++ b/pkg/grpc/grpc.go @@ -28,12 +28,15 @@ func (s *serverImplementation) Status(_ context.Context, in *pb.StatusRequest) ( return &pb.StatusResponse{Ready: true}, nil } -func (s *serverImplementation) EvaluatePizza(_ context.Context, in *pb.PizzaEvaluationRequest) (*pb.PizzaEvaluationResponse, error) { +func (s *serverImplementation) RatePizza(_ context.Context, in *pb.PizzaRatingRequest) (*pb.PizzaRatingResponse, error) { var rating int32 - if len(in.Ingredients) > 0 && in.Dough != "" { + if len(in.Ingredients) > 0 { rating = rand.Int31n(6) } - return &pb.PizzaEvaluationResponse{ + if in.Dough != "" && rating < 5 { + rating += rand.Int31n(2) + } + return &pb.PizzaRatingResponse{ StarsRating: rating, }, nil } diff --git a/pkg/grpc/quickpizza/quickpizza.pb.go b/pkg/grpc/quickpizza/quickpizza.pb.go index 95e370bc..a5745380 100644 --- a/pkg/grpc/quickpizza/quickpizza.pb.go +++ b/pkg/grpc/quickpizza/quickpizza.pb.go @@ -102,7 +102,7 @@ func (x *StatusResponse) GetReady() bool { return false } -type PizzaEvaluationRequest struct { +type PizzaRatingRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -111,20 +111,20 @@ type PizzaEvaluationRequest struct { Dough string `protobuf:"bytes,2,opt,name=dough,proto3" json:"dough,omitempty"` } -func (x *PizzaEvaluationRequest) Reset() { - *x = PizzaEvaluationRequest{} +func (x *PizzaRatingRequest) Reset() { + *x = PizzaRatingRequest{} mi := &file_proto_quickpizza_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *PizzaEvaluationRequest) String() string { +func (x *PizzaRatingRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*PizzaEvaluationRequest) ProtoMessage() {} +func (*PizzaRatingRequest) ProtoMessage() {} -func (x *PizzaEvaluationRequest) ProtoReflect() protoreflect.Message { +func (x *PizzaRatingRequest) ProtoReflect() protoreflect.Message { mi := &file_proto_quickpizza_proto_msgTypes[2] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -136,26 +136,26 @@ func (x *PizzaEvaluationRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use PizzaEvaluationRequest.ProtoReflect.Descriptor instead. -func (*PizzaEvaluationRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use PizzaRatingRequest.ProtoReflect.Descriptor instead. +func (*PizzaRatingRequest) Descriptor() ([]byte, []int) { return file_proto_quickpizza_proto_rawDescGZIP(), []int{2} } -func (x *PizzaEvaluationRequest) GetIngredients() []string { +func (x *PizzaRatingRequest) GetIngredients() []string { if x != nil { return x.Ingredients } return nil } -func (x *PizzaEvaluationRequest) GetDough() string { +func (x *PizzaRatingRequest) GetDough() string { if x != nil { return x.Dough } return "" } -type PizzaEvaluationResponse struct { +type PizzaRatingResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -163,20 +163,20 @@ type PizzaEvaluationResponse struct { StarsRating int32 `protobuf:"varint,1,opt,name=stars_rating,json=starsRating,proto3" json:"stars_rating,omitempty"` } -func (x *PizzaEvaluationResponse) Reset() { - *x = PizzaEvaluationResponse{} +func (x *PizzaRatingResponse) Reset() { + *x = PizzaRatingResponse{} mi := &file_proto_quickpizza_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *PizzaEvaluationResponse) String() string { +func (x *PizzaRatingResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*PizzaEvaluationResponse) ProtoMessage() {} +func (*PizzaRatingResponse) ProtoMessage() {} -func (x *PizzaEvaluationResponse) ProtoReflect() protoreflect.Message { +func (x *PizzaRatingResponse) ProtoReflect() protoreflect.Message { mi := &file_proto_quickpizza_proto_msgTypes[3] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -188,12 +188,12 @@ func (x *PizzaEvaluationResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use PizzaEvaluationResponse.ProtoReflect.Descriptor instead. -func (*PizzaEvaluationResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use PizzaRatingResponse.ProtoReflect.Descriptor instead. +func (*PizzaRatingResponse) Descriptor() ([]byte, []int) { return file_proto_quickpizza_proto_rawDescGZIP(), []int{3} } -func (x *PizzaEvaluationResponse) GetStarsRating() int32 { +func (x *PizzaRatingResponse) GetStarsRating() int32 { if x != nil { return x.StarsRating } @@ -208,29 +208,27 @@ var file_proto_quickpizza_proto_rawDesc = []byte{ 0x69, 0x7a, 0x7a, 0x61, 0x22, 0x0f, 0x0a, 0x0d, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x26, 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x22, 0x50, 0x0a, - 0x16, 0x50, 0x69, 0x7a, 0x7a, 0x61, 0x45, 0x76, 0x61, 0x6c, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x6e, 0x67, 0x72, 0x65, - 0x64, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, - 0x67, 0x72, 0x65, 0x64, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x6f, 0x75, - 0x67, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x6f, 0x75, 0x67, 0x68, 0x22, - 0x3c, 0x0a, 0x17, 0x50, 0x69, 0x7a, 0x7a, 0x61, 0x45, 0x76, 0x61, 0x6c, 0x75, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x74, - 0x61, 0x72, 0x73, 0x5f, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x73, 0x52, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x32, 0xa5, 0x01, - 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x41, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x19, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x2e, 0x53, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x71, 0x75, - 0x69, 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x5a, 0x0a, 0x0d, 0x45, 0x76, 0x61, - 0x6c, 0x75, 0x61, 0x74, 0x65, 0x50, 0x69, 0x7a, 0x7a, 0x61, 0x12, 0x22, 0x2e, 0x71, 0x75, 0x69, - 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x2e, 0x50, 0x69, 0x7a, 0x7a, 0x61, 0x45, 0x76, 0x61, - 0x6c, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x22, 0x4c, 0x0a, + 0x12, 0x50, 0x69, 0x7a, 0x7a, 0x61, 0x52, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x6e, 0x67, 0x72, 0x65, 0x64, 0x69, 0x65, 0x6e, + 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, 0x67, 0x72, 0x65, 0x64, + 0x69, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x6f, 0x75, 0x67, 0x68, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x6f, 0x75, 0x67, 0x68, 0x22, 0x38, 0x0a, 0x13, 0x50, + 0x69, 0x7a, 0x7a, 0x61, 0x52, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x74, 0x61, 0x72, 0x73, 0x5f, 0x72, 0x61, 0x74, 0x69, + 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x73, 0x52, + 0x61, 0x74, 0x69, 0x6e, 0x67, 0x32, 0x99, 0x01, 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x41, + 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x19, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, + 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, + 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x4e, 0x0a, 0x09, 0x52, 0x61, 0x74, 0x65, 0x50, 0x69, 0x7a, 0x7a, 0x61, 0x12, 0x1e, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x2e, 0x50, 0x69, 0x7a, 0x7a, - 0x61, 0x45, 0x76, 0x61, 0x6c, 0x75, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x15, 0x5a, 0x13, 0x70, 0x6b, 0x67, 0x2f, 0x67, 0x72, 0x70, - 0x63, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x52, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, + 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x2e, 0x50, 0x69, 0x7a, 0x7a, + 0x61, 0x52, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x42, 0x15, 0x5a, 0x13, 0x70, 0x6b, 0x67, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x71, 0x75, + 0x69, 0x63, 0x6b, 0x70, 0x69, 0x7a, 0x7a, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -247,16 +245,16 @@ func file_proto_quickpizza_proto_rawDescGZIP() []byte { var file_proto_quickpizza_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_proto_quickpizza_proto_goTypes = []any{ - (*StatusRequest)(nil), // 0: quickpizza.StatusRequest - (*StatusResponse)(nil), // 1: quickpizza.StatusResponse - (*PizzaEvaluationRequest)(nil), // 2: quickpizza.PizzaEvaluationRequest - (*PizzaEvaluationResponse)(nil), // 3: quickpizza.PizzaEvaluationResponse + (*StatusRequest)(nil), // 0: quickpizza.StatusRequest + (*StatusResponse)(nil), // 1: quickpizza.StatusResponse + (*PizzaRatingRequest)(nil), // 2: quickpizza.PizzaRatingRequest + (*PizzaRatingResponse)(nil), // 3: quickpizza.PizzaRatingResponse } var file_proto_quickpizza_proto_depIdxs = []int32{ 0, // 0: quickpizza.GRPC.Status:input_type -> quickpizza.StatusRequest - 2, // 1: quickpizza.GRPC.EvaluatePizza:input_type -> quickpizza.PizzaEvaluationRequest + 2, // 1: quickpizza.GRPC.RatePizza:input_type -> quickpizza.PizzaRatingRequest 1, // 2: quickpizza.GRPC.Status:output_type -> quickpizza.StatusResponse - 3, // 3: quickpizza.GRPC.EvaluatePizza:output_type -> quickpizza.PizzaEvaluationResponse + 3, // 3: quickpizza.GRPC.RatePizza:output_type -> quickpizza.PizzaRatingResponse 2, // [2:4] is the sub-list for method output_type 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name diff --git a/pkg/grpc/quickpizza/quickpizza_grpc.pb.go b/pkg/grpc/quickpizza/quickpizza_grpc.pb.go index b79d06c1..6fc1fe29 100644 --- a/pkg/grpc/quickpizza/quickpizza_grpc.pb.go +++ b/pkg/grpc/quickpizza/quickpizza_grpc.pb.go @@ -20,8 +20,8 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - GRPC_Status_FullMethodName = "/quickpizza.GRPC/Status" - GRPC_EvaluatePizza_FullMethodName = "/quickpizza.GRPC/EvaluatePizza" + GRPC_Status_FullMethodName = "/quickpizza.GRPC/Status" + GRPC_RatePizza_FullMethodName = "/quickpizza.GRPC/RatePizza" ) // GRPCClient is the client API for GRPC service. @@ -29,7 +29,7 @@ const ( // 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 GRPCClient interface { Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) - EvaluatePizza(ctx context.Context, in *PizzaEvaluationRequest, opts ...grpc.CallOption) (*PizzaEvaluationResponse, error) + RatePizza(ctx context.Context, in *PizzaRatingRequest, opts ...grpc.CallOption) (*PizzaRatingResponse, error) } type gRPCClient struct { @@ -50,10 +50,10 @@ func (c *gRPCClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc return out, nil } -func (c *gRPCClient) EvaluatePizza(ctx context.Context, in *PizzaEvaluationRequest, opts ...grpc.CallOption) (*PizzaEvaluationResponse, error) { +func (c *gRPCClient) RatePizza(ctx context.Context, in *PizzaRatingRequest, opts ...grpc.CallOption) (*PizzaRatingResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(PizzaEvaluationResponse) - err := c.cc.Invoke(ctx, GRPC_EvaluatePizza_FullMethodName, in, out, cOpts...) + out := new(PizzaRatingResponse) + err := c.cc.Invoke(ctx, GRPC_RatePizza_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -65,7 +65,7 @@ func (c *gRPCClient) EvaluatePizza(ctx context.Context, in *PizzaEvaluationReque // for forward compatibility. type GRPCServer interface { Status(context.Context, *StatusRequest) (*StatusResponse, error) - EvaluatePizza(context.Context, *PizzaEvaluationRequest) (*PizzaEvaluationResponse, error) + RatePizza(context.Context, *PizzaRatingRequest) (*PizzaRatingResponse, error) mustEmbedUnimplementedGRPCServer() } @@ -79,8 +79,8 @@ type UnimplementedGRPCServer struct{} func (UnimplementedGRPCServer) Status(context.Context, *StatusRequest) (*StatusResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Status not implemented") } -func (UnimplementedGRPCServer) EvaluatePizza(context.Context, *PizzaEvaluationRequest) (*PizzaEvaluationResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method EvaluatePizza not implemented") +func (UnimplementedGRPCServer) RatePizza(context.Context, *PizzaRatingRequest) (*PizzaRatingResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RatePizza not implemented") } func (UnimplementedGRPCServer) mustEmbedUnimplementedGRPCServer() {} func (UnimplementedGRPCServer) testEmbeddedByValue() {} @@ -121,20 +121,20 @@ func _GRPC_Status_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } -func _GRPC_EvaluatePizza_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(PizzaEvaluationRequest) +func _GRPC_RatePizza_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PizzaRatingRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(GRPCServer).EvaluatePizza(ctx, in) + return srv.(GRPCServer).RatePizza(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: GRPC_EvaluatePizza_FullMethodName, + FullMethod: GRPC_RatePizza_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GRPCServer).EvaluatePizza(ctx, req.(*PizzaEvaluationRequest)) + return srv.(GRPCServer).RatePizza(ctx, req.(*PizzaRatingRequest)) } return interceptor(ctx, in, info, handler) } @@ -151,8 +151,8 @@ var GRPC_ServiceDesc = grpc.ServiceDesc{ Handler: _GRPC_Status_Handler, }, { - MethodName: "EvaluatePizza", - Handler: _GRPC_EvaluatePizza_Handler, + MethodName: "RatePizza", + Handler: _GRPC_RatePizza_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/proto/quickpizza.proto b/proto/quickpizza.proto index 14c93260..60f84406 100644 --- a/proto/quickpizza.proto +++ b/proto/quickpizza.proto @@ -4,7 +4,7 @@ package quickpizza; service GRPC { rpc Status(StatusRequest) returns (StatusResponse) {} - rpc EvaluatePizza(PizzaEvaluationRequest) returns (PizzaEvaluationResponse) {} + rpc RatePizza(PizzaRatingRequest) returns (PizzaRatingResponse) {} } message StatusRequest { @@ -14,11 +14,11 @@ message StatusResponse { bool ready = 1; } -message PizzaEvaluationRequest { +message PizzaRatingRequest { repeated string ingredients = 1; string dough = 2; } -message PizzaEvaluationResponse { +message PizzaRatingResponse { int32 stars_rating = 1; }