Author: Paolo Lulli <paolo@lulli.net>
Grpc compiles
protobuf/generate.sh | 6 protobuf/metric.proto | 32 - protobuf/yats-grpc.proto | 49 +++ server/crudpb/metric.pb.go | 430 -------------------------- server/crudpb/metric_grpc.pb.go | 133 -------- server/grpc/metric-grpc-client.go | 48 ++ server/grpc/metric-grpc-server.go | 41 +- server/proto/yats-grpc.pb.go | 533 +++++++++++++++++++++++++++++++++ server/proto/yats-grpc_grpc.pb.go | 133 ++++++++
diff --git a/protobuf/generate.sh b/protobuf/generate.sh index 2e4ff1c69cb072fe8042b018190b8d7fd615ce3a..9b3950b91d7711072f9d8704e352ce60037d7994 100755 --- a/protobuf/generate.sh +++ b/protobuf/generate.sh @@ -2,14 +2,14 @@ #! /bin/bash -x cd $(dirname $0) -TARGET_DIR="../server/crudpb/" +TARGET_DIR="../server/proto/" -SOURCES="metric.proto" +SOURCES="yats-grpc.proto" for s in ${SOURCES}; do protoc --go_out=${TARGET_DIR}\ --go_opt=paths=source_relative\ --go-grpc_out=${TARGET_DIR}\ --go-grpc_opt=paths=source_relative\ - metric.proto + ${s} done diff --git a/protobuf/metric.proto b/protobuf/metric.proto deleted file mode 100644 index 650d1564a0573f088909257cdd03f7b2e6b41702..0000000000000000000000000000000000000000 --- a/protobuf/metric.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; - -package crud; - -option go_package = "yats/crudpb"; - -message Metric { - string id = 1; - string name = 2; - string description = 3; -} - -message CreateMetricRequest { - Metric metric = 1; -} - -message CreateMetricResponse { - Metric metric = 1; -} - -message ReadMetricRequest { - string id = 1; -} - -message ReadMetricResponse { - Metric metric = 1; -} - -service CRUDService { - rpc CreateMetric(CreateMetricRequest) returns (CreateMetricResponse); - rpc ReadMetric(ReadMetricRequest) returns (ReadMetricResponse); -} diff --git a/protobuf/yats-grpc.proto b/protobuf/yats-grpc.proto new file mode 100644 index 0000000000000000000000000000000000000000..d1df430f9692585b9ababfa69391fdc2e1225ad9 --- /dev/null +++ b/protobuf/yats-grpc.proto @@ -0,0 +1,49 @@ +/** + * Yats - yats + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Paolo Lulli <kevwe.com> + * @copyright Paolo Lulli 2024 + */ + +syntax = "proto3"; + +package crud; + +option go_package = "yats/proto"; + +message Metric { + string id_client = 1; + int64 mtime = 2; + string name = 3; + string value = 4; +} + +message Event { + string id_client = 1; + int64 etime = 2; + string name = 3; +} + +message CreateMetricRequest { + Metric metric = 1; +} + +message CreateMetricResponse { + Metric metric = 1; +} + +message CreateEventRequest { + Event event = 1; +} + +message CreateEventResponse { + Event event = 1; +} + +service YatsGrpcService { + rpc CreateMetric(CreateMetricRequest) returns (CreateMetricResponse); + rpc CreateEvent(CreateEventRequest) returns (CreateEventResponse); +} diff --git a/server/crudpb/metric.pb.go b/server/crudpb/metric.pb.go deleted file mode 100644 index 3ff5674ccc73df495de9e7760a122cc18b995106..0000000000000000000000000000000000000000 --- a/server/crudpb/metric.pb.go +++ /dev/null @@ -1,430 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.1 -// protoc v3.21.12 -// source: metric.proto - -package crudpb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Metric struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` -} - -func (x *Metric) Reset() { - *x = Metric{} - if protoimpl.UnsafeEnabled { - mi := &file_metric_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Metric) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Metric) ProtoMessage() {} - -func (x *Metric) ProtoReflect() protoreflect.Message { - mi := &file_metric_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 Metric.ProtoReflect.Descriptor instead. -func (*Metric) Descriptor() ([]byte, []int) { - return file_metric_proto_rawDescGZIP(), []int{0} -} - -func (x *Metric) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *Metric) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Metric) GetDescription() string { - if x != nil { - return x.Description - } - return "" -} - -type CreateMetricRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Metric *Metric `protobuf:"bytes,1,opt,name=metric,proto3" json:"metric,omitempty"` -} - -func (x *CreateMetricRequest) Reset() { - *x = CreateMetricRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_metric_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateMetricRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateMetricRequest) ProtoMessage() {} - -func (x *CreateMetricRequest) ProtoReflect() protoreflect.Message { - mi := &file_metric_proto_msgTypes[1] - 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 CreateMetricRequest.ProtoReflect.Descriptor instead. -func (*CreateMetricRequest) Descriptor() ([]byte, []int) { - return file_metric_proto_rawDescGZIP(), []int{1} -} - -func (x *CreateMetricRequest) GetMetric() *Metric { - if x != nil { - return x.Metric - } - return nil -} - -type CreateMetricResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Metric *Metric `protobuf:"bytes,1,opt,name=metric,proto3" json:"metric,omitempty"` -} - -func (x *CreateMetricResponse) Reset() { - *x = CreateMetricResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_metric_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CreateMetricResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateMetricResponse) ProtoMessage() {} - -func (x *CreateMetricResponse) ProtoReflect() protoreflect.Message { - mi := &file_metric_proto_msgTypes[2] - 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 CreateMetricResponse.ProtoReflect.Descriptor instead. -func (*CreateMetricResponse) Descriptor() ([]byte, []int) { - return file_metric_proto_rawDescGZIP(), []int{2} -} - -func (x *CreateMetricResponse) GetMetric() *Metric { - if x != nil { - return x.Metric - } - return nil -} - -type ReadMetricRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *ReadMetricRequest) Reset() { - *x = ReadMetricRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_metric_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ReadMetricRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ReadMetricRequest) ProtoMessage() {} - -func (x *ReadMetricRequest) ProtoReflect() protoreflect.Message { - mi := &file_metric_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 ReadMetricRequest.ProtoReflect.Descriptor instead. -func (*ReadMetricRequest) Descriptor() ([]byte, []int) { - return file_metric_proto_rawDescGZIP(), []int{3} -} - -func (x *ReadMetricRequest) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -type ReadMetricResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Metric *Metric `protobuf:"bytes,1,opt,name=metric,proto3" json:"metric,omitempty"` -} - -func (x *ReadMetricResponse) Reset() { - *x = ReadMetricResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_metric_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ReadMetricResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ReadMetricResponse) ProtoMessage() {} - -func (x *ReadMetricResponse) ProtoReflect() protoreflect.Message { - mi := &file_metric_proto_msgTypes[4] - 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 ReadMetricResponse.ProtoReflect.Descriptor instead. -func (*ReadMetricResponse) Descriptor() ([]byte, []int) { - return file_metric_proto_rawDescGZIP(), []int{4} -} - -func (x *ReadMetricResponse) GetMetric() *Metric { - if x != nil { - return x.Metric - } - return nil -} - -var File_metric_proto protoreflect.FileDescriptor - -var file_metric_proto_rawDesc = []byte{ - 0x0a, 0x0c, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, - 0x63, 0x72, 0x75, 0x64, 0x22, 0x4e, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x0e, - 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3b, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x06, 0x6d, - 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x72, - 0x75, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, - 0x63, 0x22, 0x3c, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, - 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x06, 0x6d, 0x65, 0x74, - 0x72, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x72, 0x75, 0x64, - 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x22, - 0x23, 0x0a, 0x11, 0x52, 0x65, 0x61, 0x64, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x02, 0x69, 0x64, 0x22, 0x3a, 0x0a, 0x12, 0x52, 0x65, 0x61, 0x64, 0x4d, 0x65, 0x74, 0x72, - 0x69, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x06, 0x6d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x72, 0x75, - 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x32, 0x95, 0x01, 0x0a, 0x0b, 0x43, 0x52, 0x55, 0x44, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x12, 0x45, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x12, 0x19, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x63, 0x72, - 0x75, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a, 0x0a, 0x52, 0x65, 0x61, 0x64, 0x4d, - 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x17, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x52, 0x65, 0x61, - 0x64, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, - 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0d, 0x5a, 0x0b, 0x79, 0x61, 0x74, 0x73, - 0x2f, 0x63, 0x72, 0x75, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_metric_proto_rawDescOnce sync.Once - file_metric_proto_rawDescData = file_metric_proto_rawDesc -) - -func file_metric_proto_rawDescGZIP() []byte { - file_metric_proto_rawDescOnce.Do(func() { - file_metric_proto_rawDescData = protoimpl.X.CompressGZIP(file_metric_proto_rawDescData) - }) - return file_metric_proto_rawDescData -} - -var file_metric_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_metric_proto_goTypes = []interface{}{ - (*Metric)(nil), // 0: crud.Metric - (*CreateMetricRequest)(nil), // 1: crud.CreateMetricRequest - (*CreateMetricResponse)(nil), // 2: crud.CreateMetricResponse - (*ReadMetricRequest)(nil), // 3: crud.ReadMetricRequest - (*ReadMetricResponse)(nil), // 4: crud.ReadMetricResponse -} -var file_metric_proto_depIdxs = []int32{ - 0, // 0: crud.CreateMetricRequest.metric:type_name -> crud.Metric - 0, // 1: crud.CreateMetricResponse.metric:type_name -> crud.Metric - 0, // 2: crud.ReadMetricResponse.metric:type_name -> crud.Metric - 1, // 3: crud.CRUDService.CreateMetric:input_type -> crud.CreateMetricRequest - 3, // 4: crud.CRUDService.ReadMetric:input_type -> crud.ReadMetricRequest - 2, // 5: crud.CRUDService.CreateMetric:output_type -> crud.CreateMetricResponse - 4, // 6: crud.CRUDService.ReadMetric:output_type -> crud.ReadMetricResponse - 5, // [5:7] is the sub-list for method output_type - 3, // [3:5] 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 -} - -func init() { file_metric_proto_init() } -func file_metric_proto_init() { - if File_metric_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_metric_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Metric); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_metric_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateMetricRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_metric_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateMetricResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_metric_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReadMetricRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_metric_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReadMetricResponse); 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{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_metric_proto_rawDesc, - NumEnums: 0, - NumMessages: 5, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_metric_proto_goTypes, - DependencyIndexes: file_metric_proto_depIdxs, - MessageInfos: file_metric_proto_msgTypes, - }.Build() - File_metric_proto = out.File - file_metric_proto_rawDesc = nil - file_metric_proto_goTypes = nil - file_metric_proto_depIdxs = nil -} diff --git a/server/crudpb/metric_grpc.pb.go b/server/crudpb/metric_grpc.pb.go deleted file mode 100644 index f1b91a4df38b95f238cacdc7cd2ed2777d8d79be..0000000000000000000000000000000000000000 --- a/server/crudpb/metric_grpc.pb.go +++ /dev/null @@ -1,133 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package crudpb - -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. -const _ = grpc.SupportPackageIsVersion7 - -// CRUDServiceClient is the client API for CRUDService 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 CRUDServiceClient interface { - CreateMetric(ctx context.Context, in *CreateMetricRequest, opts ...grpc.CallOption) (*CreateMetricResponse, error) - ReadMetric(ctx context.Context, in *ReadMetricRequest, opts ...grpc.CallOption) (*ReadMetricResponse, error) -} - -type cRUDServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewCRUDServiceClient(cc grpc.ClientConnInterface) CRUDServiceClient { - return &cRUDServiceClient{cc} -} - -func (c *cRUDServiceClient) CreateMetric(ctx context.Context, in *CreateMetricRequest, opts ...grpc.CallOption) (*CreateMetricResponse, error) { - out := new(CreateMetricResponse) - err := c.cc.Invoke(ctx, "/crud.CRUDService/CreateMetric", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *cRUDServiceClient) ReadMetric(ctx context.Context, in *ReadMetricRequest, opts ...grpc.CallOption) (*ReadMetricResponse, error) { - out := new(ReadMetricResponse) - err := c.cc.Invoke(ctx, "/crud.CRUDService/ReadMetric", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// CRUDServiceServer is the server API for CRUDService service. -// All implementations must embed UnimplementedCRUDServiceServer -// for forward compatibility -type CRUDServiceServer interface { - CreateMetric(context.Context, *CreateMetricRequest) (*CreateMetricResponse, error) - ReadMetric(context.Context, *ReadMetricRequest) (*ReadMetricResponse, error) - mustEmbedUnimplementedCRUDServiceServer() -} - -// UnimplementedCRUDServiceServer must be embedded to have forward compatible implementations. -type UnimplementedCRUDServiceServer struct { -} - -func (UnimplementedCRUDServiceServer) CreateMetric(context.Context, *CreateMetricRequest) (*CreateMetricResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateMetric not implemented") -} -func (UnimplementedCRUDServiceServer) ReadMetric(context.Context, *ReadMetricRequest) (*ReadMetricResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ReadMetric not implemented") -} -func (UnimplementedCRUDServiceServer) mustEmbedUnimplementedCRUDServiceServer() {} - -// UnsafeCRUDServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to CRUDServiceServer will -// result in compilation errors. -type UnsafeCRUDServiceServer interface { - mustEmbedUnimplementedCRUDServiceServer() -} - -func RegisterCRUDServiceServer(s *grpc.Server, srv CRUDServiceServer) { - s.RegisterService(&_CRUDService_serviceDesc, srv) -} - -func _CRUDService_CreateMetric_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateMetricRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CRUDServiceServer).CreateMetric(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/crud.CRUDService/CreateMetric", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CRUDServiceServer).CreateMetric(ctx, req.(*CreateMetricRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _CRUDService_ReadMetric_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReadMetricRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CRUDServiceServer).ReadMetric(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/crud.CRUDService/ReadMetric", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CRUDServiceServer).ReadMetric(ctx, req.(*ReadMetricRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _CRUDService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "crud.CRUDService", - HandlerType: (*CRUDServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateMetric", - Handler: _CRUDService_CreateMetric_Handler, - }, - { - MethodName: "ReadMetric", - Handler: _CRUDService_ReadMetric_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "metric.proto", -} diff --git a/server/grpc/metric-grpc-client.go b/server/grpc/metric-grpc-client.go new file mode 100644 index 0000000000000000000000000000000000000000..aeb543e23dd6aefea44148d7434f8d409e26f4be --- /dev/null +++ b/server/grpc/metric-grpc-client.go @@ -0,0 +1,48 @@ +/** + * Yats - yats + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Paolo Lulli <kevwe.com> + * @copyright Paolo Lulli 2024 + */ + +package main + +import ( + "context" + "log" + "time" + "yats-server/proto" + + "google.golang.org/grpc" +) + +func mains() { + conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithBlock()) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer conn.Close() + c := proto.NewYatsGrpcServiceClient(conn) + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + // Create an item + item := &proto.Metric{IdClient: "DefaultIdClient", Name: "Item 1", Mtime: time.Now().UnixMilli(), Value: "This is the value"} + res, err := c.CreateMetric(ctx, &proto.CreateMetricRequest{Metric: item}) + if err != nil { + log.Fatalf("could not create item: %v", err) + } + log.Printf("Item created: %v", res.GetMetric()) + + // Read an item + resRead, err := c.ReadMetric(ctx, &proto.ReadMetricRequest{Id: "1"}) + if err != nil { + log.Fatalf("could not read item: %v", err) + } + log.Printf("Item read: %v", resRead.GetMetric()) + +} diff --git a/server/grpc/metric-grpc-server.go b/server/grpc/metric-grpc-server.go index 74aec8f0fc70189dac0d4293c09d176afec334f4..2384268684706c59bddd5a06d1ba418b0a20808b 100644 --- a/server/grpc/metric-grpc-server.go +++ b/server/grpc/metric-grpc-server.go @@ -1,41 +1,48 @@ -package crudpb +/** + * Yats - yats + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Paolo Lulli <kevwe.com> + * @copyright Paolo Lulli 2024 + */ + +package main import ( "context" "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "log" "net" - "yats-server/crudpb" + "yats-server/proto" ) type server struct { - crudpb.UnimplementedCRUDServiceServer - metrics map[string]*crudpb.Metric + proto.UnimplementedYatsGrpcServiceServer + metrics map[string]*proto.Metric + events map[string]*proto.Event } -func (s *server) CreateMetric(ctx context.Context, req *crudpb.CreateMetricRequest) (*crudpb.CreateMetricResponse, error) { +func (s *server) CreateMetric(ctx context.Context, req *proto.CreateMetricRequest) (*proto.CreateMetricResponse, error) { metric := req.GetMetric() - s.metrics[metric.Id] = metric - return &crudpb.CreateMetricResponse{Metric: metric}, nil + s.metrics[metric.IdClient] = metric + return &proto.CreateMetricResponse{Metric: metric}, nil } -func (s *server) ReadMetric(ctx context.Context, req *crudpb.ReadMetricRequest) (*crudpb.ReadMetricResponse, error) { - metric, exists := s.metrics[req.GetId()] - if !exists { - return nil, status.Errorf(codes.NotFound, "metric not found") - } - return &crudpb.ReadMetricResponse{Metric: metric}, nil +func (s *server) CreateEvent(ctx context.Context, req *proto.CreateEventRequest) (*proto.CreateEventResponse, error) { + event := req.GetEvent() + s.events[event.IdClient] = event + return &proto.CreateEventResponse{Event: event}, nil } -func main() { +func main_server() { lis, err := net.Listen("tcp", ":50051") if err != nil { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() - crudpb.RegisterCRUDServiceServer(s, &server{metrics: make(map[string]*crudpb.Metric)}) + proto.RegisterYatsGrpcServiceServer(s, &server{metrics: make(map[string]*proto.Metric)}) log.Println("Server is running on port 50051") if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/server/proto/yats-grpc.pb.go b/server/proto/yats-grpc.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..822507d2708d77ffcce1d0a8181451cf9dcc805a --- /dev/null +++ b/server/proto/yats-grpc.pb.go @@ -0,0 +1,533 @@ +//* +// Yats - yats +// +// This file is licensed under the Affero General Public License version 3 or +// later. See the COPYING file. +// +// @author Paolo Lulli <kevwe.com> +// @copyright Paolo Lulli 2024 + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.21.12 +// source: yats-grpc.proto + +package proto + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Metric struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IdClient string `protobuf:"bytes,1,opt,name=id_client,json=idClient,proto3" json:"id_client,omitempty"` + Mtime int64 `protobuf:"varint,2,opt,name=mtime,proto3" json:"mtime,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + Value string `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *Metric) Reset() { + *x = Metric{} + if protoimpl.UnsafeEnabled { + mi := &file_yats_grpc_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Metric) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Metric) ProtoMessage() {} + +func (x *Metric) ProtoReflect() protoreflect.Message { + mi := &file_yats_grpc_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 Metric.ProtoReflect.Descriptor instead. +func (*Metric) Descriptor() ([]byte, []int) { + return file_yats_grpc_proto_rawDescGZIP(), []int{0} +} + +func (x *Metric) GetIdClient() string { + if x != nil { + return x.IdClient + } + return "" +} + +func (x *Metric) GetMtime() int64 { + if x != nil { + return x.Mtime + } + return 0 +} + +func (x *Metric) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Metric) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +type Event struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IdClient string `protobuf:"bytes,1,opt,name=id_client,json=idClient,proto3" json:"id_client,omitempty"` + Etime int64 `protobuf:"varint,2,opt,name=etime,proto3" json:"etime,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *Event) Reset() { + *x = Event{} + if protoimpl.UnsafeEnabled { + mi := &file_yats_grpc_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Event) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Event) ProtoMessage() {} + +func (x *Event) ProtoReflect() protoreflect.Message { + mi := &file_yats_grpc_proto_msgTypes[1] + 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 Event.ProtoReflect.Descriptor instead. +func (*Event) Descriptor() ([]byte, []int) { + return file_yats_grpc_proto_rawDescGZIP(), []int{1} +} + +func (x *Event) GetIdClient() string { + if x != nil { + return x.IdClient + } + return "" +} + +func (x *Event) GetEtime() int64 { + if x != nil { + return x.Etime + } + return 0 +} + +func (x *Event) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type CreateMetricRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Metric *Metric `protobuf:"bytes,1,opt,name=metric,proto3" json:"metric,omitempty"` +} + +func (x *CreateMetricRequest) Reset() { + *x = CreateMetricRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_yats_grpc_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateMetricRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateMetricRequest) ProtoMessage() {} + +func (x *CreateMetricRequest) ProtoReflect() protoreflect.Message { + mi := &file_yats_grpc_proto_msgTypes[2] + 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 CreateMetricRequest.ProtoReflect.Descriptor instead. +func (*CreateMetricRequest) Descriptor() ([]byte, []int) { + return file_yats_grpc_proto_rawDescGZIP(), []int{2} +} + +func (x *CreateMetricRequest) GetMetric() *Metric { + if x != nil { + return x.Metric + } + return nil +} + +type CreateMetricResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Metric *Metric `protobuf:"bytes,1,opt,name=metric,proto3" json:"metric,omitempty"` +} + +func (x *CreateMetricResponse) Reset() { + *x = CreateMetricResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_yats_grpc_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateMetricResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateMetricResponse) ProtoMessage() {} + +func (x *CreateMetricResponse) ProtoReflect() protoreflect.Message { + mi := &file_yats_grpc_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 CreateMetricResponse.ProtoReflect.Descriptor instead. +func (*CreateMetricResponse) Descriptor() ([]byte, []int) { + return file_yats_grpc_proto_rawDescGZIP(), []int{3} +} + +func (x *CreateMetricResponse) GetMetric() *Metric { + if x != nil { + return x.Metric + } + return nil +} + +type CreateEventRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Event *Event `protobuf:"bytes,1,opt,name=event,proto3" json:"event,omitempty"` +} + +func (x *CreateEventRequest) Reset() { + *x = CreateEventRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_yats_grpc_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateEventRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateEventRequest) ProtoMessage() {} + +func (x *CreateEventRequest) ProtoReflect() protoreflect.Message { + mi := &file_yats_grpc_proto_msgTypes[4] + 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 CreateEventRequest.ProtoReflect.Descriptor instead. +func (*CreateEventRequest) Descriptor() ([]byte, []int) { + return file_yats_grpc_proto_rawDescGZIP(), []int{4} +} + +func (x *CreateEventRequest) GetEvent() *Event { + if x != nil { + return x.Event + } + return nil +} + +type CreateEventResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Event *Event `protobuf:"bytes,1,opt,name=event,proto3" json:"event,omitempty"` +} + +func (x *CreateEventResponse) Reset() { + *x = CreateEventResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_yats_grpc_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateEventResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateEventResponse) ProtoMessage() {} + +func (x *CreateEventResponse) ProtoReflect() protoreflect.Message { + mi := &file_yats_grpc_proto_msgTypes[5] + 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 CreateEventResponse.ProtoReflect.Descriptor instead. +func (*CreateEventResponse) Descriptor() ([]byte, []int) { + return file_yats_grpc_proto_rawDescGZIP(), []int{5} +} + +func (x *CreateEventResponse) GetEvent() *Event { + if x != nil { + return x.Event + } + return nil +} + +var File_yats_grpc_proto protoreflect.FileDescriptor + +var file_yats_grpc_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x79, 0x61, 0x74, 0x73, 0x2d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x04, 0x63, 0x72, 0x75, 0x64, 0x22, 0x65, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x72, 0x69, + 0x63, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x64, 0x5f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x69, 0x64, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x6d, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6d, + 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x4e, + 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x64, 0x5f, 0x63, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x69, 0x64, 0x43, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x05, 0x65, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3b, + 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x4d, 0x65, 0x74, + 0x72, 0x69, 0x63, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x22, 0x3c, 0x0a, 0x14, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, + 0x63, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x22, 0x37, 0x0a, 0x12, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x21, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, + 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x22, 0x38, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x65, 0x76, 0x65, + 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x32, 0x9c, 0x01, 0x0a, + 0x0f, 0x59, 0x61, 0x74, 0x73, 0x47, 0x72, 0x70, 0x63, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x45, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, + 0x12, 0x19, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, + 0x74, 0x72, 0x69, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x63, 0x72, + 0x75, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x19, 0x2e, 0x63, 0x72, 0x75, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0c, 0x5a, 0x0a, 0x79, + 0x61, 0x74, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, +} + +var ( + file_yats_grpc_proto_rawDescOnce sync.Once + file_yats_grpc_proto_rawDescData = file_yats_grpc_proto_rawDesc +) + +func file_yats_grpc_proto_rawDescGZIP() []byte { + file_yats_grpc_proto_rawDescOnce.Do(func() { + file_yats_grpc_proto_rawDescData = protoimpl.X.CompressGZIP(file_yats_grpc_proto_rawDescData) + }) + return file_yats_grpc_proto_rawDescData +} + +var file_yats_grpc_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_yats_grpc_proto_goTypes = []interface{}{ + (*Metric)(nil), // 0: crud.Metric + (*Event)(nil), // 1: crud.Event + (*CreateMetricRequest)(nil), // 2: crud.CreateMetricRequest + (*CreateMetricResponse)(nil), // 3: crud.CreateMetricResponse + (*CreateEventRequest)(nil), // 4: crud.CreateEventRequest + (*CreateEventResponse)(nil), // 5: crud.CreateEventResponse +} +var file_yats_grpc_proto_depIdxs = []int32{ + 0, // 0: crud.CreateMetricRequest.metric:type_name -> crud.Metric + 0, // 1: crud.CreateMetricResponse.metric:type_name -> crud.Metric + 1, // 2: crud.CreateEventRequest.event:type_name -> crud.Event + 1, // 3: crud.CreateEventResponse.event:type_name -> crud.Event + 2, // 4: crud.YatsGrpcService.CreateMetric:input_type -> crud.CreateMetricRequest + 4, // 5: crud.YatsGrpcService.CreateEvent:input_type -> crud.CreateEventRequest + 3, // 6: crud.YatsGrpcService.CreateMetric:output_type -> crud.CreateMetricResponse + 5, // 7: crud.YatsGrpcService.CreateEvent:output_type -> crud.CreateEventResponse + 6, // [6:8] is the sub-list for method output_type + 4, // [4:6] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name +} + +func init() { file_yats_grpc_proto_init() } +func file_yats_grpc_proto_init() { + if File_yats_grpc_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_yats_grpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Metric); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_yats_grpc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Event); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_yats_grpc_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateMetricRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_yats_grpc_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateMetricResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_yats_grpc_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateEventRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_yats_grpc_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateEventResponse); 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{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_yats_grpc_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_yats_grpc_proto_goTypes, + DependencyIndexes: file_yats_grpc_proto_depIdxs, + MessageInfos: file_yats_grpc_proto_msgTypes, + }.Build() + File_yats_grpc_proto = out.File + file_yats_grpc_proto_rawDesc = nil + file_yats_grpc_proto_goTypes = nil + file_yats_grpc_proto_depIdxs = nil +} diff --git a/server/proto/yats-grpc_grpc.pb.go b/server/proto/yats-grpc_grpc.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..bfff6aab2b504957e76d76794d852b5831dd04a3 --- /dev/null +++ b/server/proto/yats-grpc_grpc.pb.go @@ -0,0 +1,133 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. + +package proto + +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. +const _ = grpc.SupportPackageIsVersion7 + +// YatsGrpcServiceClient is the client API for YatsGrpcService 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 YatsGrpcServiceClient interface { + CreateMetric(ctx context.Context, in *CreateMetricRequest, opts ...grpc.CallOption) (*CreateMetricResponse, error) + CreateEvent(ctx context.Context, in *CreateEventRequest, opts ...grpc.CallOption) (*CreateEventResponse, error) +} + +type yatsGrpcServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewYatsGrpcServiceClient(cc grpc.ClientConnInterface) YatsGrpcServiceClient { + return &yatsGrpcServiceClient{cc} +} + +func (c *yatsGrpcServiceClient) CreateMetric(ctx context.Context, in *CreateMetricRequest, opts ...grpc.CallOption) (*CreateMetricResponse, error) { + out := new(CreateMetricResponse) + err := c.cc.Invoke(ctx, "/crud.YatsGrpcService/CreateMetric", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *yatsGrpcServiceClient) CreateEvent(ctx context.Context, in *CreateEventRequest, opts ...grpc.CallOption) (*CreateEventResponse, error) { + out := new(CreateEventResponse) + err := c.cc.Invoke(ctx, "/crud.YatsGrpcService/CreateEvent", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// YatsGrpcServiceServer is the server API for YatsGrpcService service. +// All implementations must embed UnimplementedYatsGrpcServiceServer +// for forward compatibility +type YatsGrpcServiceServer interface { + CreateMetric(context.Context, *CreateMetricRequest) (*CreateMetricResponse, error) + CreateEvent(context.Context, *CreateEventRequest) (*CreateEventResponse, error) + mustEmbedUnimplementedYatsGrpcServiceServer() +} + +// UnimplementedYatsGrpcServiceServer must be embedded to have forward compatible implementations. +type UnimplementedYatsGrpcServiceServer struct { +} + +func (UnimplementedYatsGrpcServiceServer) CreateMetric(context.Context, *CreateMetricRequest) (*CreateMetricResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateMetric not implemented") +} +func (UnimplementedYatsGrpcServiceServer) CreateEvent(context.Context, *CreateEventRequest) (*CreateEventResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateEvent not implemented") +} +func (UnimplementedYatsGrpcServiceServer) mustEmbedUnimplementedYatsGrpcServiceServer() {} + +// UnsafeYatsGrpcServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to YatsGrpcServiceServer will +// result in compilation errors. +type UnsafeYatsGrpcServiceServer interface { + mustEmbedUnimplementedYatsGrpcServiceServer() +} + +func RegisterYatsGrpcServiceServer(s *grpc.Server, srv YatsGrpcServiceServer) { + s.RegisterService(&_YatsGrpcService_serviceDesc, srv) +} + +func _YatsGrpcService_CreateMetric_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateMetricRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(YatsGrpcServiceServer).CreateMetric(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/crud.YatsGrpcService/CreateMetric", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(YatsGrpcServiceServer).CreateMetric(ctx, req.(*CreateMetricRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _YatsGrpcService_CreateEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateEventRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(YatsGrpcServiceServer).CreateEvent(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/crud.YatsGrpcService/CreateEvent", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(YatsGrpcServiceServer).CreateEvent(ctx, req.(*CreateEventRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _YatsGrpcService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "crud.YatsGrpcService", + HandlerType: (*YatsGrpcServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateMetric", + Handler: _YatsGrpcService_CreateMetric_Handler, + }, + { + MethodName: "CreateEvent", + Handler: _YatsGrpcService_CreateEvent_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "yats-grpc.proto", +}