diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..de0e2e8ec5032ee9c3265d0a892af67d7a41d10d --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module gitee.com/wheat-os/wheat-cache-dashboard + +go 1.17 + +require ( + google.golang.org/grpc v1.41.0 + google.golang.org/protobuf v1.27.1 +) + +require ( + github.com/golang/protobuf v1.5.0 // indirect + golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect + golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect + golang.org/x/text v0.3.0 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect +) diff --git a/main.go b/main.go new file mode 100644 index 0000000000000000000000000000000000000000..3f64638c5e2e9ee805ca196433ce957dd5b823ed --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "gitee.com/wheat-os/wheat-cache-dashboard/service/server" + +func main() { + server.Server() +} diff --git a/makefile b/makefile new file mode 100644 index 0000000000000000000000000000000000000000..472ce051a7766f496e9de7ba8b41576300ffd458 --- /dev/null +++ b/makefile @@ -0,0 +1,2 @@ +proto: + @python ./shell/protoBuild.py \ No newline at end of file diff --git a/protobuf/product.proto b/protobuf/product.proto new file mode 100644 index 0000000000000000000000000000000000000000..64c7d9a6e8d20291616afc00fae9195e388f460c --- /dev/null +++ b/protobuf/product.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +option go_package = "service/basic-block"; + +message ProductRequest { + int32 req_id = 1; +} + +message ProductResponse { + int32 resp_id = 1; +} + +service ProductService { + rpc GetResponseId(ProductRequest) returns (ProductResponse); +} \ No newline at end of file diff --git a/service/basic-block/product.pb.go b/service/basic-block/product.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..a956710b0a3060d25a7e8c21ed90dd9d7fc442c3 --- /dev/null +++ b/service/basic-block/product.pb.go @@ -0,0 +1,295 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.17.3 +// source: product.proto + +package basic_block + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 ProductRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ReqId int32 `protobuf:"varint,1,opt,name=req_id,json=reqId,proto3" json:"req_id,omitempty"` +} + +func (x *ProductRequest) Reset() { + *x = ProductRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_product_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductRequest) ProtoMessage() {} + +func (x *ProductRequest) ProtoReflect() protoreflect.Message { + mi := &file_product_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 ProductRequest.ProtoReflect.Descriptor instead. +func (*ProductRequest) Descriptor() ([]byte, []int) { + return file_product_proto_rawDescGZIP(), []int{0} +} + +func (x *ProductRequest) GetReqId() int32 { + if x != nil { + return x.ReqId + } + return 0 +} + +type ProductResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + RespId int32 `protobuf:"varint,1,opt,name=resp_id,json=respId,proto3" json:"resp_id,omitempty"` +} + +func (x *ProductResponse) Reset() { + *x = ProductResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_product_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ProductResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ProductResponse) ProtoMessage() {} + +func (x *ProductResponse) ProtoReflect() protoreflect.Message { + mi := &file_product_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 ProductResponse.ProtoReflect.Descriptor instead. +func (*ProductResponse) Descriptor() ([]byte, []int) { + return file_product_proto_rawDescGZIP(), []int{1} +} + +func (x *ProductResponse) GetRespId() int32 { + if x != nil { + return x.RespId + } + return 0 +} + +var File_product_proto protoreflect.FileDescriptor + +var file_product_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x27, 0x0a, 0x0e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x15, 0x0a, 0x06, 0x72, 0x65, 0x71, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x05, 0x72, 0x65, 0x71, 0x49, 0x64, 0x22, 0x2a, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x64, + 0x75, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x72, + 0x65, 0x73, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x72, 0x65, + 0x73, 0x70, 0x49, 0x64, 0x32, 0x44, 0x0a, 0x0e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x32, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x49, 0x64, 0x12, 0x0f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x15, 0x5a, 0x13, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x2d, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_product_proto_rawDescOnce sync.Once + file_product_proto_rawDescData = file_product_proto_rawDesc +) + +func file_product_proto_rawDescGZIP() []byte { + file_product_proto_rawDescOnce.Do(func() { + file_product_proto_rawDescData = protoimpl.X.CompressGZIP(file_product_proto_rawDescData) + }) + return file_product_proto_rawDescData +} + +var file_product_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_product_proto_goTypes = []interface{}{ + (*ProductRequest)(nil), // 0: ProductRequest + (*ProductResponse)(nil), // 1: ProductResponse +} +var file_product_proto_depIdxs = []int32{ + 0, // 0: ProductService.GetResponseId:input_type -> ProductRequest + 1, // 1: ProductService.GetResponseId:output_type -> ProductResponse + 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 +} + +func init() { file_product_proto_init() } +func file_product_proto_init() { + if File_product_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_product_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_product_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ProductResponse); 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_product_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_product_proto_goTypes, + DependencyIndexes: file_product_proto_depIdxs, + MessageInfos: file_product_proto_msgTypes, + }.Build() + File_product_proto = out.File + file_product_proto_rawDesc = nil + file_product_proto_goTypes = nil + file_product_proto_depIdxs = nil +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// 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.SupportPackageIsVersion6 + +// ProductServiceClient is the client API for ProductService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ProductServiceClient interface { + GetResponseId(ctx context.Context, in *ProductRequest, opts ...grpc.CallOption) (*ProductResponse, error) +} + +type productServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewProductServiceClient(cc grpc.ClientConnInterface) ProductServiceClient { + return &productServiceClient{cc} +} + +func (c *productServiceClient) GetResponseId(ctx context.Context, in *ProductRequest, opts ...grpc.CallOption) (*ProductResponse, error) { + out := new(ProductResponse) + err := c.cc.Invoke(ctx, "/ProductService/GetResponseId", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ProductServiceServer is the server API for ProductService service. +type ProductServiceServer interface { + GetResponseId(context.Context, *ProductRequest) (*ProductResponse, error) +} + +// UnimplementedProductServiceServer can be embedded to have forward compatible implementations. +type UnimplementedProductServiceServer struct { +} + +func (*UnimplementedProductServiceServer) GetResponseId(context.Context, *ProductRequest) (*ProductResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetResponseId not implemented") +} + +func RegisterProductServiceServer(s *grpc.Server, srv *ProdService) { + s.RegisterService(&_ProductService_serviceDesc, srv) +} + +func _ProductService_GetResponseId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ProductRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServiceServer).GetResponseId(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ProductService/GetResponseId", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServiceServer).GetResponseId(ctx, req.(*ProductRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _ProductService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ProductService", + HandlerType: (*ProductServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetResponseId", + Handler: _ProductService_GetResponseId_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "product.proto", +} diff --git a/service/basic-block/service.go b/service/basic-block/service.go new file mode 100644 index 0000000000000000000000000000000000000000..2be0dc5ad1801cd9e66f239d1e497f197136d923 --- /dev/null +++ b/service/basic-block/service.go @@ -0,0 +1,12 @@ +package basic_block + +import ( + "context" +) + +type ProdService struct { +} + +func (s *ProdService) GetResponseId(ctx context.Context, request *ProductRequest) (*ProductResponse, error) { + return &ProductResponse{RespId: request.ReqId}, nil +} diff --git a/service/server/service.go b/service/server/service.go new file mode 100644 index 0000000000000000000000000000000000000000..b16b24b646ed6cec26f2fa7b855776e7530af771 --- /dev/null +++ b/service/server/service.go @@ -0,0 +1,21 @@ +package server + +import ( + basicBlock "gitee.com/wheat-os/wheat-cache-dashboard/service/basic-block" + "google.golang.org/grpc" + "log" + "net" +) + +func Server() { + rpcServer := grpc.NewServer() + basicBlock.RegisterProductServiceServer(rpcServer, new(basicBlock.ProdService)) + + listen, err := net.Listen("tcp", ":9999") + if err != nil { + log.Fatal("监听失败", err) + } + + _ = rpcServer.Serve(listen) + +} diff --git a/shell/protoBuild.py b/shell/protoBuild.py new file mode 100644 index 0000000000000000000000000000000000000000..f95c57279484dae19451cb09509cd62fae2e28d3 --- /dev/null +++ b/shell/protoBuild.py @@ -0,0 +1,24 @@ +import os + +sysPath = os.getcwd() +protoPath = f"{sysPath}/protobuf" +# protoc --proto_path=./ --go_out=plugins=grpc:../service Product.proto + +comm = """ +protoc --proto_path={} --go_out=plugins=grpc:{} {} +""" + + +def out_proto(): + for root, dirs, files in os.walk(protoPath): + for f in files: + commend = comm.format(protoPath, sysPath, f).strip() + err = os.system(commend) + if err: + print(f, err) + else: + print(f, "--> success") + + +if __name__ == '__main__': + out_proto()