From d8a2f84bca46c3f21be11dba7fc5663e4af610e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=A4=D0=B5=D0=B4=D0=BE=D1=80=D1=8E=D0=BA?= Date: Wed, 30 Nov 2022 14:24:24 +0300 Subject: [PATCH] Prepare callID for logger --- docker-compose.yml | 2 +- network/header.pb.go | 61 +++++++++++++-------- network/metadata.pb.go | 120 +++++++++-------------------------------- protobuf | 2 +- ytfunction.go | 8 ++- ytfunction_test.go | 38 +++++++++++++ 6 files changed, 112 insertions(+), 119 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 180cbcd..fda8515 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" services: nats: - image: nats:2.9.3-scratch + image: nats:2.9.8-scratch ports: - "4222:4222" - "8222:8222" diff --git a/network/header.pb.go b/network/header.pb.go index c74bf0d..941bdaa 100644 --- a/network/header.pb.go +++ b/network/header.pb.go @@ -34,6 +34,8 @@ type Header struct { Method string `protobuf:"bytes,7,opt,name=method,proto3" json:"method,omitempty"` Domain string `protobuf:"bytes,8,opt,name=domain,proto3" json:"domain,omitempty"` Project string `protobuf:"bytes,9,opt,name=project,proto3" json:"project,omitempty"` + CallID string `protobuf:"bytes,10,opt,name=callID,proto3" json:"callID,omitempty"` + CallPrevID string `protobuf:"bytes,11,opt,name=callPrevID,proto3" json:"callPrevID,omitempty"` } func (x *Header) Reset() { @@ -131,6 +133,20 @@ func (x *Header) GetProject() string { return "" } +func (x *Header) GetCallID() string { + if x != nil { + return x.CallID + } + return "" +} + +func (x *Header) GetCallPrevID() string { + if x != nil { + return x.CallPrevID + } + return "" +} + var File_protobuf_header_proto protoreflect.FileDescriptor var file_protobuf_header_proto_rawDesc = []byte{ @@ -139,7 +155,7 @@ var file_protobuf_header_proto_rawDesc = []byte{ 0x1a, 0x1a, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x2d, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x61, 0x72, 0x74, - 0x2d, 0x66, 0x6f, 0x72, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb0, 0x05, 0x0a, 0x06, + 0x2d, 0x66, 0x6f, 0x72, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe8, 0x05, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x36, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, @@ -165,26 +181,29 @@ var file_protobuf_header_proto_rawDesc = []byte{ 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x1a, 0x3a, 0x0a, - 0x0c, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x54, 0x0a, 0x0e, 0x51, 0x75, 0x65, - 0x72, 0x79, 0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x6e, - 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4f, 0x66, 0x53, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, - 0x39, 0x0a, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, - 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, - 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0b, - 0x5a, 0x09, 0x2e, 0x2f, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x16, 0x0a, + 0x06, 0x63, 0x61, 0x6c, 0x6c, 0x49, 0x44, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, + 0x61, 0x6c, 0x6c, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x61, 0x6c, 0x6c, 0x50, 0x72, 0x65, + 0x76, 0x49, 0x44, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x61, 0x6c, 0x6c, 0x50, + 0x72, 0x65, 0x76, 0x49, 0x44, 0x1a, 0x3a, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x1a, 0x54, 0x0a, 0x0e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x4c, + 0x69, 0x73, 0x74, 0x4f, 0x66, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x52, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x39, 0x0a, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, + 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x65, + 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x6e, 0x65, 0x74, 0x77, + 0x6f, 0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/network/metadata.pb.go b/network/metadata.pb.go index ed3d5b7..8ee1008 100644 --- a/network/metadata.pb.go +++ b/network/metadata.pb.go @@ -20,66 +20,17 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type Metadata_PackageType int32 - -const ( - Metadata_TYPE_REQUEST Metadata_PackageType = 0 // Пакет запроса - Metadata_TYPE_RESPONSE Metadata_PackageType = 1 // Пакет ответа - Metadata_TYPE_STREAM Metadata_PackageType = 2 // Пакет потока, который не требует возврата результата (обратного вызова) -) - -// Enum value maps for Metadata_PackageType. -var ( - Metadata_PackageType_name = map[int32]string{ - 0: "TYPE_REQUEST", - 1: "TYPE_RESPONSE", - 2: "TYPE_STREAM", - } - Metadata_PackageType_value = map[string]int32{ - "TYPE_REQUEST": 0, - "TYPE_RESPONSE": 1, - "TYPE_STREAM": 2, - } -) - -func (x Metadata_PackageType) Enum() *Metadata_PackageType { - p := new(Metadata_PackageType) - *p = x - return p -} - -func (x Metadata_PackageType) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Metadata_PackageType) Descriptor() protoreflect.EnumDescriptor { - return file_protobuf_metadata_proto_enumTypes[0].Descriptor() -} - -func (Metadata_PackageType) Type() protoreflect.EnumType { - return &file_protobuf_metadata_proto_enumTypes[0] -} - -func (x Metadata_PackageType) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Metadata_PackageType.Descriptor instead. -func (Metadata_PackageType) EnumDescriptor() ([]byte, []int) { - return file_protobuf_metadata_proto_rawDescGZIP(), []int{0, 0} -} - type Metadata struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - PackageType Metadata_PackageType `protobuf:"varint,1,opt,name=packageType,proto3,enum=network.Metadata_PackageType" json:"packageType,omitempty"` - FuncName string `protobuf:"bytes,2,opt,name=funcName,proto3" json:"funcName,omitempty"` - QueueCallback string `protobuf:"bytes,3,opt,name=queueCallback,proto3" json:"queueCallback,omitempty"` - CallResponseID string `protobuf:"bytes,4,opt,name=callResponseID,proto3" json:"callResponseID,omitempty"` - CallID string `protobuf:"bytes,5,opt,name=callID,proto3" json:"callID,omitempty"` - CallFrom string `protobuf:"bytes,6,opt,name=callFrom,proto3" json:"callFrom,omitempty"` + // PackageType packageType = 1; + FuncName string `protobuf:"bytes,2,opt,name=funcName,proto3" json:"funcName,omitempty"` + QueueCallback string `protobuf:"bytes,3,opt,name=queueCallback,proto3" json:"queueCallback,omitempty"` + CallResponseID string `protobuf:"bytes,4,opt,name=callResponseID,proto3" json:"callResponseID,omitempty"` + CallID string `protobuf:"bytes,5,opt,name=callID,proto3" json:"callID,omitempty"` + CallFrom string `protobuf:"bytes,6,opt,name=callFrom,proto3" json:"callFrom,omitempty"` } func (x *Metadata) Reset() { @@ -114,13 +65,6 @@ func (*Metadata) Descriptor() ([]byte, []int) { return file_protobuf_metadata_proto_rawDescGZIP(), []int{0} } -func (x *Metadata) GetPackageType() Metadata_PackageType { - if x != nil { - return x.PackageType - } - return Metadata_TYPE_REQUEST -} - func (x *Metadata) GetFuncName() string { if x != nil { return x.FuncName @@ -161,27 +105,19 @@ var File_protobuf_metadata_proto protoreflect.FileDescriptor var file_protobuf_metadata_proto_rawDesc = []byte{ 0x0a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, - 0x72, 0x6b, 0x22, 0xae, 0x02, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, - 0x3f, 0x0a, 0x0b, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1d, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x54, - 0x79, 0x70, 0x65, 0x52, 0x0b, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, - 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x24, 0x0a, 0x0d, - 0x71, 0x75, 0x65, 0x75, 0x65, 0x43, 0x61, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0d, 0x71, 0x75, 0x65, 0x75, 0x65, 0x43, 0x61, 0x6c, 0x6c, 0x62, 0x61, - 0x63, 0x6b, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x49, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x63, 0x61, 0x6c, 0x6c, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, - 0x6c, 0x6c, 0x49, 0x44, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x61, 0x6c, 0x6c, - 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x6c, 0x6c, 0x46, 0x72, 0x6f, 0x6d, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x6c, 0x6c, 0x46, 0x72, 0x6f, 0x6d, 0x22, 0x43, - 0x0a, 0x0b, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, - 0x0c, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, 0x54, 0x10, 0x00, 0x12, - 0x11, 0x0a, 0x0d, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, - 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x54, 0x52, 0x45, 0x41, - 0x4d, 0x10, 0x02, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x6b, 0x22, 0xa8, 0x01, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, + 0x1a, 0x0a, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x71, + 0x75, 0x65, 0x75, 0x65, 0x43, 0x61, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0d, 0x71, 0x75, 0x65, 0x75, 0x65, 0x43, 0x61, 0x6c, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x49, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x63, 0x61, 0x6c, 0x6c, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, 0x6c, + 0x6c, 0x49, 0x44, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x61, 0x6c, 0x6c, 0x49, + 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x6c, 0x6c, 0x46, 0x72, 0x6f, 0x6d, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x6c, 0x6c, 0x46, 0x72, 0x6f, 0x6d, 0x42, 0x0b, 0x5a, + 0x09, 0x2e, 0x2f, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -196,19 +132,16 @@ func file_protobuf_metadata_proto_rawDescGZIP() []byte { return file_protobuf_metadata_proto_rawDescData } -var file_protobuf_metadata_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_protobuf_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_protobuf_metadata_proto_goTypes = []interface{}{ - (Metadata_PackageType)(0), // 0: network.Metadata.PackageType - (*Metadata)(nil), // 1: network.Metadata + (*Metadata)(nil), // 0: network.Metadata } var file_protobuf_metadata_proto_depIdxs = []int32{ - 0, // 0: network.Metadata.packageType:type_name -> network.Metadata.PackageType - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] 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 + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] 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 } func init() { file_protobuf_metadata_proto_init() } @@ -235,14 +168,13 @@ func file_protobuf_metadata_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_protobuf_metadata_proto_rawDesc, - NumEnums: 1, + NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_protobuf_metadata_proto_goTypes, DependencyIndexes: file_protobuf_metadata_proto_depIdxs, - EnumInfos: file_protobuf_metadata_proto_enumTypes, MessageInfos: file_protobuf_metadata_proto_msgTypes, }.Build() File_protobuf_metadata_proto = out.File diff --git a/protobuf b/protobuf index 25149bd..0614836 160000 --- a/protobuf +++ b/protobuf @@ -1 +1 @@ -Subproject commit 25149bdedc7b24d7d67bce812adfdc7200cce6fd +Subproject commit 0614836308d39991470fabf39be6caf2f0dfba68 diff --git a/ytfunction.go b/ytfunction.go index e109104..fc953ac 100644 --- a/ytfunction.go +++ b/ytfunction.go @@ -129,6 +129,7 @@ func (fDesc *funcDesc) worker() { type CallbackFunc struct { F func(err error, header *network.Header, result []byte) TimeCall time.Time + //Metadata *network.Metadata } // Сервер инстанса @@ -422,7 +423,7 @@ func (serve *Serve) acceptVerify(accept string) bool { // Асинхронный вызов функции func (serve *Serve) CallAsync(name string, header *network.Header, payload []byte, f func(err error, header *network.Header, result []byte)) { metadata := &network.Metadata{ - PackageType: network.Metadata_TYPE_REQUEST, + //PackageType: network.Metadata_TYPE_REQUEST, FuncName: name, QueueCallback: serve.queueCallback, CallID: uuid.NewV4().String(), @@ -431,6 +432,8 @@ func (serve *Serve) CallAsync(name string, header *network.Header, payload []byt if header == nil { header = &network.Header{} } + header.CallPrevID = header.CallID + header.CallID = metadata.CallID header.Project = serve.projectName pkg := network.Function{ Header: header, @@ -448,6 +451,7 @@ func (serve *Serve) CallAsync(name string, header *network.Header, payload []byt callback := &CallbackFunc{ F: f, TimeCall: time.Now(), + //Metadata: pkg.Metadata, } serve.callbackFuncsMutex.Lock() defer serve.callbackFuncsMutex.Unlock() @@ -477,7 +481,7 @@ func (serve *Serve) Call(name string, header *network.Header, payload []byte) (r // Вызов функции как поток без ожидания возврата результата func (serve *Serve) CallStream(name string, header *network.Header, payload []byte) (err error) { metadata := &network.Metadata{ - PackageType: network.Metadata_TYPE_REQUEST, + //PackageType: network.Metadata_TYPE_STREAM, FuncName: name, QueueCallback: serve.queueCallback, CallID: uuid.NewV4().String(), diff --git a/ytfunction_test.go b/ytfunction_test.go index 7f007fb..6808061 100644 --- a/ytfunction_test.go +++ b/ytfunction_test.go @@ -122,3 +122,41 @@ func TestCallFunction(t *testing.T) { t.Errorf("got \"my test\", but expect \"%s\"", v) } } + +func TestCallFunctionDouble(t *testing.T) { + var err error + err = serve.RegisterFunction("testFuncSimple1", func(header *network.Header, paylod []byte) (result []byte, err error) { + /*header.ResponseHeaders["test"] = "my test" + return []byte("world"), nil*/ + result, _, err = serve.Call("default.test.testFuncSimple2", header, []byte("Hello")) + return result, err + }) + if err != nil { + t.Error("Has error: ", err) + return + } + err = serve.RegisterFunction("testFuncSimple2", func(header *network.Header, paylod []byte) (result []byte, err error) { + header.ResponseHeaders["test"] = "my test" + return []byte("world"), nil + }) + if err != nil { + t.Error("Has error: ", err) + return + } + var result []byte + var header *network.Header + result, header, err = serve.Call("default.test.testFuncSimple1", nil, []byte("Hello")) + if err != nil { + t.Error(err) + return + } + if string(result) != "world" { + t.Error("Function not returned \"world\"") + return + } + if v, ok := header.ResponseHeaders["test"]; !ok { + t.Errorf("not set response header") + } else if v != "my test" { + t.Errorf("got \"my test\", but expect \"%s\"", v) + } +}