duyong mac 2 месяцев назад
Родитель
Сommit
170d366f65

+ 10 - 8
dyrpc/client/client.go

@@ -24,7 +24,7 @@ func main() {
 	//	grpclog.Fatalf("Failed to create TLS credentials %v", err)
 	//}
 
-	conn, err := grpc.Dial(":8081", grpc.WithTransportCredentials(helper.GetCredentials(certFile, keyFile, caFile)))
+	conn, err := grpc.NewClient(":8081", grpc.WithTransportCredentials(helper.GetCredentials(certFile, keyFile, caFile)))
 	if err != nil {
 		log.Fatalf("failed to dial: %v", err)
 	}
@@ -53,13 +53,15 @@ func main() {
 	fmt.Println(prodInfo)
 
 	orderClient := prod.NewOrderServiceClient(conn)
-	newOrderRes, err := orderClient.NewOrder(context.Background(), &prod.ProdMain{
-		OrderId:    1,
-		OrderNo:    "123",
-		UserId:     456,
-		OrderMoney: 50.5,
-		OrderTime: &timestamppb.Timestamp{
-			Seconds: time.Now().Unix(),
+	newOrderRes, err := orderClient.NewOrder(context.Background(), &prod.OrderRequest{
+		ProdMain: &prod.ProdMain{
+			OrderId:    1,
+			OrderNo:    "123",
+			UserId:     456,
+			OrderMoney: 50.5,
+			OrderTime: &timestamppb.Timestamp{
+				Seconds: time.Now().Unix(),
+			},
 		},
 	})
 	if err != nil {

+ 6 - 1
dyrpc/httpserver/main.go

@@ -19,7 +19,12 @@ const (
 func main() {
 	gwmux := runtime.NewServeMux()
 	opt := []grpc.DialOption{grpc.WithTransportCredentials(helper.GetCredentials(certFile, keyFile, caFile))}
-	err := prod.RegisterProdServiceHandlerFromEndpoint(context.Background(), gwmux, "localhost:8081", opt)
+	endpoint := "localhost:8081"
+	err := prod.RegisterProdServiceHandlerFromEndpoint(context.Background(), gwmux, endpoint, opt)
+	if err != nil {
+		log.Fatal(err)
+	}
+	err = prod.RegisterOrderServiceHandlerFromEndpoint(context.Background(), gwmux, endpoint, opt)
 	if err != nil {
 		log.Fatal(err)
 	}

+ 3 - 0
dyrpc/prod.sh

@@ -4,4 +4,7 @@ cd ./proto
 protoc --go_out=../services --go-grpc_out=../services   models.proto
 protoc --go_out=../services --go-grpc_out=../services   prod.proto
 protoc --go_out=../services --go-grpc_out=../services   order.proto
+
+protoc -I . --grpc-gateway_out ../services prod.proto
+protoc -I . --grpc-gateway_out ../services order.proto
 cd ..

+ 9 - 1
dyrpc/proto/order.proto

@@ -6,6 +6,9 @@ option go_package = "/prod";
 import "google/api/annotations.proto";
 import "models.proto";
 
+message OrderRequest{
+    ProdMain prod_main = 1;
+}
 
 message OrderResponse{
   string status=1;
@@ -13,5 +16,10 @@ message OrderResponse{
 }
 
 service OrderService{
-  rpc NewOrder(ProdMain)returns(OrderResponse){}
+  rpc NewOrder(OrderRequest)returns(OrderResponse){
+    option (google.api.http) = {
+      post: "/v1/orders"
+      body: "prod_main"
+    };
+  }
 }

+ 10 - 0
dyrpc/proto语法.md

@@ -56,3 +56,13 @@ import "models.proto";
 rpc GetProdInfo(ProdRequest)returns(ProdModel){}
  // 注意在同一包下时可以这样使用,如果models.proto中声明的package不是services包,则在使用时应该用 包名.ProdModel
 ```
+
+### 字段验证库
+
+https://github.com/bufbuild/protoc-gen-validate
+
+
+### 流模式
+
+
+

+ 2 - 2
dyrpc/readme.md

@@ -4,9 +4,9 @@ go的gRPC框架 https://github.com/grpc/grpc-go
 # protobuf 
 protobuf协议编译器
 https://github.com/protocolbuffers/protobuf/tags
-https://github.com/golang/protobuf  
-##  golang 编译器插件
 
+##  golang 编译器插件
+https://github.com/golang/protobuf  
 对于Golang来说,称为protoc-gen-go。
 
 不过在这儿有个小小的坑,github.com/golang/protobuf/protoc-gen-go和google.golang.org/protobuf/cmd/protoc-gen-go是不同的。

+ 2 - 3
dyrpc/services/order_service.go

@@ -4,15 +4,14 @@ import (
 	"context"
 	"dy-test/dyrpc/services/prod"
 	"fmt"
-	"time"
 )
 
 type OrderService struct {
 	prod.UnimplementedOrderServiceServer
 }
 
-func (o *OrderService) NewOrder(ctx context.Context, main *prod.ProdMain) (*prod.OrderResponse, error) {
-	fmt.Println(main.OrderTime.AsTime().Local().Format(time.DateTime))
+func (o *OrderService) NewOrder(ctx context.Context, main *prod.OrderRequest) (*prod.OrderResponse, error) {
+	fmt.Println(main.ProdMain.OrderTime)
 	return &prod.OrderResponse{
 		Status:  "123",
 		Message: "456",

+ 92 - 25
dyrpc/services/prod/order.pb.go

@@ -21,6 +21,53 @@ const (
 	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
 )
 
+type OrderRequest struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	ProdMain *ProdMain `protobuf:"bytes,1,opt,name=prod_main,json=prodMain,proto3" json:"prod_main,omitempty"`
+}
+
+func (x *OrderRequest) Reset() {
+	*x = OrderRequest{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_order_proto_msgTypes[0]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *OrderRequest) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*OrderRequest) ProtoMessage() {}
+
+func (x *OrderRequest) ProtoReflect() protoreflect.Message {
+	mi := &file_order_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 OrderRequest.ProtoReflect.Descriptor instead.
+func (*OrderRequest) Descriptor() ([]byte, []int) {
+	return file_order_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *OrderRequest) GetProdMain() *ProdMain {
+	if x != nil {
+		return x.ProdMain
+	}
+	return nil
+}
+
 type OrderResponse struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -33,7 +80,7 @@ type OrderResponse struct {
 func (x *OrderResponse) Reset() {
 	*x = OrderResponse{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_order_proto_msgTypes[0]
+		mi := &file_order_proto_msgTypes[1]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -46,7 +93,7 @@ func (x *OrderResponse) String() string {
 func (*OrderResponse) ProtoMessage() {}
 
 func (x *OrderResponse) ProtoReflect() protoreflect.Message {
-	mi := &file_order_proto_msgTypes[0]
+	mi := &file_order_proto_msgTypes[1]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -59,7 +106,7 @@ func (x *OrderResponse) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use OrderResponse.ProtoReflect.Descriptor instead.
 func (*OrderResponse) Descriptor() ([]byte, []int) {
-	return file_order_proto_rawDescGZIP(), []int{0}
+	return file_order_proto_rawDescGZIP(), []int{1}
 }
 
 func (x *OrderResponse) GetStatus() string {
@@ -83,17 +130,23 @@ var file_order_proto_rawDesc = []byte{
 	0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f,
 	0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e,
 	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0c, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x72,
-	0x6f, 0x74, 0x6f, 0x22, 0x41, 0x0a, 0x0d, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70,
-	0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01,
-	0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07,
-	0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d,
-	0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x49, 0x0a, 0x0c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x53,
-	0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x39, 0x0a, 0x08, 0x4e, 0x65, 0x77, 0x4f, 0x72, 0x64,
-	0x65, 0x72, 0x12, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x50, 0x72,
-	0x6f, 0x64, 0x4d, 0x61, 0x69, 0x6e, 0x1a, 0x17, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
-	0x73, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
-	0x00, 0x42, 0x07, 0x5a, 0x05, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
-	0x6f, 0x33,
+	0x6f, 0x74, 0x6f, 0x22, 0x3f, 0x0a, 0x0c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75,
+	0x65, 0x73, 0x74, 0x12, 0x2f, 0x0a, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x5f, 0x6d, 0x61, 0x69, 0x6e,
+	0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
+	0x73, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x4d, 0x61, 0x69, 0x6e, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x64,
+	0x4d, 0x61, 0x69, 0x6e, 0x22, 0x41, 0x0a, 0x0d, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73,
+	0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18,
+	0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a,
+	0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
+	0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x6a, 0x0a, 0x0c, 0x4f, 0x72, 0x64, 0x65, 0x72,
+	0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5a, 0x0a, 0x08, 0x4e, 0x65, 0x77, 0x4f, 0x72,
+	0x64, 0x65, 0x72, 0x12, 0x16, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x4f,
+	0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x73, 0x65,
+	0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70,
+	0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x3a, 0x09, 0x70, 0x72,
+	0x6f, 0x64, 0x5f, 0x6d, 0x61, 0x69, 0x6e, 0x22, 0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x72, 0x64,
+	0x65, 0x72, 0x73, 0x42, 0x07, 0x5a, 0x05, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x62, 0x06, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -108,19 +161,21 @@ func file_order_proto_rawDescGZIP() []byte {
 	return file_order_proto_rawDescData
 }
 
-var file_order_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
+var file_order_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
 var file_order_proto_goTypes = []interface{}{
-	(*OrderResponse)(nil), // 0: services.OrderResponse
-	(*ProdMain)(nil),      // 1: services.ProdMain
+	(*OrderRequest)(nil),  // 0: services.OrderRequest
+	(*OrderResponse)(nil), // 1: services.OrderResponse
+	(*ProdMain)(nil),      // 2: services.ProdMain
 }
 var file_order_proto_depIdxs = []int32{
-	1, // 0: services.OrderService.NewOrder:input_type -> services.ProdMain
-	0, // 1: services.OrderService.NewOrder:output_type -> services.OrderResponse
-	1, // [1:2] is the sub-list for method output_type
-	0, // [0:1] is the sub-list for method input_type
-	0, // [0:0] is the sub-list for extension type_name
-	0, // [0:0] is the sub-list for extension extendee
-	0, // [0:0] is the sub-list for field type_name
+	2, // 0: services.OrderRequest.prod_main:type_name -> services.ProdMain
+	0, // 1: services.OrderService.NewOrder:input_type -> services.OrderRequest
+	1, // 2: services.OrderService.NewOrder:output_type -> services.OrderResponse
+	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_order_proto_init() }
@@ -131,6 +186,18 @@ func file_order_proto_init() {
 	file_models_proto_init()
 	if !protoimpl.UnsafeEnabled {
 		file_order_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*OrderRequest); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_order_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*OrderResponse); i {
 			case 0:
 				return &v.state
@@ -149,7 +216,7 @@ func file_order_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_order_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   1,
+			NumMessages:   2,
 			NumExtensions: 0,
 			NumServices:   1,
 		},

+ 163 - 0
dyrpc/services/prod/order.pb.gw.go

@@ -0,0 +1,163 @@
+// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
+// source: order.proto
+
+/*
+Package prod is a reverse proxy.
+
+It translates gRPC into RESTful JSON APIs.
+*/
+package prod
+
+import (
+	"context"
+	"io"
+	"net/http"
+
+	"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
+	"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
+	"google.golang.org/grpc"
+	"google.golang.org/grpc/codes"
+	"google.golang.org/grpc/grpclog"
+	"google.golang.org/grpc/metadata"
+	"google.golang.org/grpc/status"
+	"google.golang.org/protobuf/proto"
+)
+
+// Suppress "imported and not used" errors
+var _ codes.Code
+var _ io.Reader
+var _ status.Status
+var _ = runtime.String
+var _ = utilities.NewDoubleArray
+var _ = metadata.Join
+
+func request_OrderService_NewOrder_0(ctx context.Context, marshaler runtime.Marshaler, client OrderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+	var protoReq OrderRequest
+	var metadata runtime.ServerMetadata
+
+	if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.ProdMain); err != nil && err != io.EOF {
+		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+	}
+
+	msg, err := client.NewOrder(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
+	return msg, metadata, err
+
+}
+
+func local_request_OrderService_NewOrder_0(ctx context.Context, marshaler runtime.Marshaler, server OrderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
+	var protoReq OrderRequest
+	var metadata runtime.ServerMetadata
+
+	if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.ProdMain); err != nil && err != io.EOF {
+		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+	}
+
+	msg, err := server.NewOrder(ctx, &protoReq)
+	return msg, metadata, err
+
+}
+
+// RegisterOrderServiceHandlerServer registers the http handlers for service OrderService to "mux".
+// UnaryRPC     :call OrderServiceServer directly.
+// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
+// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterOrderServiceHandlerFromEndpoint instead.
+func RegisterOrderServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server OrderServiceServer) error {
+
+	mux.Handle("POST", pattern_OrderService_NewOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
+		ctx, cancel := context.WithCancel(req.Context())
+		defer cancel()
+		var stream runtime.ServerTransportStream
+		ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
+		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
+		var err error
+		var annotatedContext context.Context
+		annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/services.OrderService/NewOrder", runtime.WithHTTPPathPattern("/v1/orders"))
+		if err != nil {
+			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+			return
+		}
+		resp, md, err := local_request_OrderService_NewOrder_0(annotatedContext, inboundMarshaler, server, req, pathParams)
+		md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
+		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
+		if err != nil {
+			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
+			return
+		}
+
+		forward_OrderService_NewOrder_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+
+	})
+
+	return nil
+}
+
+// RegisterOrderServiceHandlerFromEndpoint is same as RegisterOrderServiceHandler but
+// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
+func RegisterOrderServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
+	conn, err := grpc.DialContext(ctx, endpoint, opts...)
+	if err != nil {
+		return err
+	}
+	defer func() {
+		if err != nil {
+			if cerr := conn.Close(); cerr != nil {
+				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
+			}
+			return
+		}
+		go func() {
+			<-ctx.Done()
+			if cerr := conn.Close(); cerr != nil {
+				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
+			}
+		}()
+	}()
+
+	return RegisterOrderServiceHandler(ctx, mux, conn)
+}
+
+// RegisterOrderServiceHandler registers the http handlers for service OrderService to "mux".
+// The handlers forward requests to the grpc endpoint over "conn".
+func RegisterOrderServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
+	return RegisterOrderServiceHandlerClient(ctx, mux, NewOrderServiceClient(conn))
+}
+
+// RegisterOrderServiceHandlerClient registers the http handlers for service OrderService
+// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "OrderServiceClient".
+// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "OrderServiceClient"
+// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
+// "OrderServiceClient" to call the correct interceptors.
+func RegisterOrderServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client OrderServiceClient) error {
+
+	mux.Handle("POST", pattern_OrderService_NewOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
+		ctx, cancel := context.WithCancel(req.Context())
+		defer cancel()
+		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
+		var err error
+		var annotatedContext context.Context
+		annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/services.OrderService/NewOrder", runtime.WithHTTPPathPattern("/v1/orders"))
+		if err != nil {
+			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
+			return
+		}
+		resp, md, err := request_OrderService_NewOrder_0(annotatedContext, inboundMarshaler, client, req, pathParams)
+		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
+		if err != nil {
+			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
+			return
+		}
+
+		forward_OrderService_NewOrder_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
+
+	})
+
+	return nil
+}
+
+var (
+	pattern_OrderService_NewOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "orders"}, ""))
+)
+
+var (
+	forward_OrderService_NewOrder_0 = runtime.ForwardResponseMessage
+)

+ 6 - 6
dyrpc/services/prod/order_grpc.pb.go

@@ -26,7 +26,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 OrderServiceClient interface {
-	NewOrder(ctx context.Context, in *ProdMain, opts ...grpc.CallOption) (*OrderResponse, error)
+	NewOrder(ctx context.Context, in *OrderRequest, opts ...grpc.CallOption) (*OrderResponse, error)
 }
 
 type orderServiceClient struct {
@@ -37,7 +37,7 @@ func NewOrderServiceClient(cc grpc.ClientConnInterface) OrderServiceClient {
 	return &orderServiceClient{cc}
 }
 
-func (c *orderServiceClient) NewOrder(ctx context.Context, in *ProdMain, opts ...grpc.CallOption) (*OrderResponse, error) {
+func (c *orderServiceClient) NewOrder(ctx context.Context, in *OrderRequest, opts ...grpc.CallOption) (*OrderResponse, error) {
 	out := new(OrderResponse)
 	err := c.cc.Invoke(ctx, OrderService_NewOrder_FullMethodName, in, out, opts...)
 	if err != nil {
@@ -50,7 +50,7 @@ func (c *orderServiceClient) NewOrder(ctx context.Context, in *ProdMain, opts ..
 // All implementations must embed UnimplementedOrderServiceServer
 // for forward compatibility
 type OrderServiceServer interface {
-	NewOrder(context.Context, *ProdMain) (*OrderResponse, error)
+	NewOrder(context.Context, *OrderRequest) (*OrderResponse, error)
 	mustEmbedUnimplementedOrderServiceServer()
 }
 
@@ -58,7 +58,7 @@ type OrderServiceServer interface {
 type UnimplementedOrderServiceServer struct {
 }
 
-func (UnimplementedOrderServiceServer) NewOrder(context.Context, *ProdMain) (*OrderResponse, error) {
+func (UnimplementedOrderServiceServer) NewOrder(context.Context, *OrderRequest) (*OrderResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method NewOrder not implemented")
 }
 func (UnimplementedOrderServiceServer) mustEmbedUnimplementedOrderServiceServer() {}
@@ -75,7 +75,7 @@ func RegisterOrderServiceServer(s grpc.ServiceRegistrar, srv OrderServiceServer)
 }
 
 func _OrderService_NewOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
-	in := new(ProdMain)
+	in := new(OrderRequest)
 	if err := dec(in); err != nil {
 		return nil, err
 	}
@@ -87,7 +87,7 @@ func _OrderService_NewOrder_Handler(srv interface{}, ctx context.Context, dec fu
 		FullMethod: OrderService_NewOrder_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
-		return srv.(OrderServiceServer).NewOrder(ctx, req.(*ProdMain))
+		return srv.(OrderServiceServer).NewOrder(ctx, req.(*OrderRequest))
 	}
 	return interceptor(ctx, in, info, handler)
 }

+ 18 - 0
dyrpc/services/prod/prod.pb.gw.go

@@ -31,6 +31,10 @@ var _ = runtime.String
 var _ = utilities.NewDoubleArray
 var _ = metadata.Join
 
+var (
+	filter_ProdService_GetProdStock_0 = &utilities.DoubleArray{Encoding: map[string]int{"prod_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
+)
+
 func request_ProdService_GetProdStock_0(ctx context.Context, marshaler runtime.Marshaler, client ProdServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
 	var protoReq ProdRequest
 	var metadata runtime.ServerMetadata
@@ -52,6 +56,13 @@ func request_ProdService_GetProdStock_0(ctx context.Context, marshaler runtime.M
 		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "prod_id", err)
 	}
 
+	if err := req.ParseForm(); err != nil {
+		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+	}
+	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ProdService_GetProdStock_0); err != nil {
+		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+	}
+
 	msg, err := client.GetProdStock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
 	return msg, metadata, err
 
@@ -78,6 +89,13 @@ func local_request_ProdService_GetProdStock_0(ctx context.Context, marshaler run
 		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "prod_id", err)
 	}
 
+	if err := req.ParseForm(); err != nil {
+		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+	}
+	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ProdService_GetProdStock_0); err != nil {
+		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+	}
+
 	msg, err := server.GetProdStock(ctx, &protoReq)
 	return msg, metadata, err