From 6eec18030687131470317e06f1e8af419da791ca Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 21 Sep 2021 19:28:14 +0800 Subject: [PATCH 1/5] refactor(proto-file): resume file --- pkg/log/define.go | 1 + pkg/log/define/define.go | 1 - pkg/lru/define.go | 3 + pkg/lru/define/define.go | 3 - pkg/middle/define.go | 1 + pkg/middle/define/define.go | 1 - pkg/proto/base.pb.go | 166 ----------------- pkg/proto/storage.pb.go | 275 ---------------------------- pkg/proto/stringx.pb.go | 355 ------------------------------------ pkg/structure/define.go | 24 --- protobuf/base.proto | 2 +- protobuf/listx.proto | 7 - protobuf/storage.proto | 23 --- protobuf/stringx.proto | 28 --- 14 files changed, 6 insertions(+), 884 deletions(-) create mode 100644 pkg/log/define.go delete mode 100644 pkg/log/define/define.go create mode 100644 pkg/lru/define.go delete mode 100644 pkg/lru/define/define.go create mode 100644 pkg/middle/define.go delete mode 100644 pkg/middle/define/define.go delete mode 100644 pkg/proto/base.pb.go delete mode 100644 pkg/proto/storage.pb.go delete mode 100644 pkg/proto/stringx.pb.go delete mode 100644 protobuf/listx.proto delete mode 100644 protobuf/storage.proto delete mode 100644 protobuf/stringx.proto diff --git a/pkg/log/define.go b/pkg/log/define.go new file mode 100644 index 0000000..7330d54 --- /dev/null +++ b/pkg/log/define.go @@ -0,0 +1 @@ +package log diff --git a/pkg/log/define/define.go b/pkg/log/define/define.go deleted file mode 100644 index 57c3969..0000000 --- a/pkg/log/define/define.go +++ /dev/null @@ -1 +0,0 @@ -package define diff --git a/pkg/lru/define.go b/pkg/lru/define.go new file mode 100644 index 0000000..2eb64ef --- /dev/null +++ b/pkg/lru/define.go @@ -0,0 +1,3 @@ +package lru + +// define diff --git a/pkg/lru/define/define.go b/pkg/lru/define/define.go deleted file mode 100644 index 8c5bf99..0000000 --- a/pkg/lru/define/define.go +++ /dev/null @@ -1,3 +0,0 @@ -package define - -// define diff --git a/pkg/middle/define.go b/pkg/middle/define.go new file mode 100644 index 0000000..94eaada --- /dev/null +++ b/pkg/middle/define.go @@ -0,0 +1 @@ +package middle diff --git a/pkg/middle/define/define.go b/pkg/middle/define/define.go deleted file mode 100644 index 57c3969..0000000 --- a/pkg/middle/define/define.go +++ /dev/null @@ -1 +0,0 @@ -package define diff --git a/pkg/proto/base.pb.go b/pkg/proto/base.pb.go deleted file mode 100644 index 7e14747..0000000 --- a/pkg/proto/base.pb.go +++ /dev/null @@ -1,166 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.3 -// source: base.proto - -package proto - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - 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 BaseKey struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Ttl int64 `protobuf:"varint,2,opt,name=ttl,proto3" json:"ttl,omitempty"` - Expire *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=expire,proto3" json:"expire,omitempty"` -} - -func (x *BaseKey) Reset() { - *x = BaseKey{} - if protoimpl.UnsafeEnabled { - mi := &file_base_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *BaseKey) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*BaseKey) ProtoMessage() {} - -func (x *BaseKey) ProtoReflect() protoreflect.Message { - mi := &file_base_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 BaseKey.ProtoReflect.Descriptor instead. -func (*BaseKey) Descriptor() ([]byte, []int) { - return file_base_proto_rawDescGZIP(), []int{0} -} - -func (x *BaseKey) GetKey() string { - if x != nil { - return x.Key - } - return "" -} - -func (x *BaseKey) GetTtl() int64 { - if x != nil { - return x.Ttl - } - return 0 -} - -func (x *BaseKey) GetExpire() *timestamppb.Timestamp { - if x != nil { - return x.Expire - } - return nil -} - -var File_base_proto protoreflect.FileDescriptor - -var file_base_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x61, 0x0a, - 0x07, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x74, - 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x74, 0x74, 0x6c, 0x12, 0x32, 0x0a, 0x06, - 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x06, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, - 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_base_proto_rawDescOnce sync.Once - file_base_proto_rawDescData = file_base_proto_rawDesc -) - -func file_base_proto_rawDescGZIP() []byte { - file_base_proto_rawDescOnce.Do(func() { - file_base_proto_rawDescData = protoimpl.X.CompressGZIP(file_base_proto_rawDescData) - }) - return file_base_proto_rawDescData -} - -var file_base_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_base_proto_goTypes = []interface{}{ - (*BaseKey)(nil), // 0: BaseKey - (*timestamppb.Timestamp)(nil), // 1: google.protobuf.Timestamp -} -var file_base_proto_depIdxs = []int32{ - 1, // 0: BaseKey.expire:type_name -> google.protobuf.Timestamp - 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 -} - -func init() { file_base_proto_init() } -func file_base_proto_init() { - if File_base_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_base_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*BaseKey); 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_base_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_base_proto_goTypes, - DependencyIndexes: file_base_proto_depIdxs, - MessageInfos: file_base_proto_msgTypes, - }.Build() - File_base_proto = out.File - file_base_proto_rawDesc = nil - file_base_proto_goTypes = nil - file_base_proto_depIdxs = nil -} diff --git a/pkg/proto/storage.pb.go b/pkg/proto/storage.pb.go deleted file mode 100644 index 219e2dc..0000000 --- a/pkg/proto/storage.pb.go +++ /dev/null @@ -1,275 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.3 -// source: storage.proto - -package proto - -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 CommendResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Result []string `protobuf:"bytes,1,rep,name=result,proto3" json:"result,omitempty"` -} - -func (x *CommendResponse) Reset() { - *x = CommendResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_storage_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CommendResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CommendResponse) ProtoMessage() {} - -func (x *CommendResponse) ProtoReflect() protoreflect.Message { - mi := &file_storage_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 CommendResponse.ProtoReflect.Descriptor instead. -func (*CommendResponse) Descriptor() ([]byte, []int) { - return file_storage_proto_rawDescGZIP(), []int{0} -} - -func (x *CommendResponse) GetResult() []string { - if x != nil { - return x.Result - } - return nil -} - -var File_storage_proto protoreflect.FileDescriptor - -var file_storage_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x0d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x29, - 0x0a, 0x0f, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0x58, 0x0a, 0x0a, 0x43, 0x6f, 0x6d, - 0x6d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x24, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x0b, - 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x43, 0x6f, - 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, - 0x03, 0x53, 0x65, 0x74, 0x12, 0x0b, 0x2e, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x10, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_storage_proto_rawDescOnce sync.Once - file_storage_proto_rawDescData = file_storage_proto_rawDesc -) - -func file_storage_proto_rawDescGZIP() []byte { - file_storage_proto_rawDescOnce.Do(func() { - file_storage_proto_rawDescData = protoimpl.X.CompressGZIP(file_storage_proto_rawDescData) - }) - return file_storage_proto_rawDescData -} - -var file_storage_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_storage_proto_goTypes = []interface{}{ - (*CommendResponse)(nil), // 0: CommendResponse - (*GetRequest)(nil), // 1: GetRequest - (*SetRequest)(nil), // 2: SetRequest -} -var file_storage_proto_depIdxs = []int32{ - 1, // 0: CommServer.Get:input_type -> GetRequest - 2, // 1: CommServer.Set:input_type -> SetRequest - 0, // 2: CommServer.Get:output_type -> CommendResponse - 0, // 3: CommServer.Set:output_type -> CommendResponse - 2, // [2:4] is the sub-list for method output_type - 0, // [0:2] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_storage_proto_init() } -func file_storage_proto_init() { - if File_storage_proto != nil { - return - } - file_stringx_proto_init() - if !protoimpl.UnsafeEnabled { - file_storage_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CommendResponse); 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_storage_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_storage_proto_goTypes, - DependencyIndexes: file_storage_proto_depIdxs, - MessageInfos: file_storage_proto_msgTypes, - }.Build() - File_storage_proto = out.File - file_storage_proto_rawDesc = nil - file_storage_proto_goTypes = nil - file_storage_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 - -// CommServerClient is the client API for CommServer service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type CommServerClient interface { - Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*CommendResponse, error) - Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*CommendResponse, error) -} - -type commServerClient struct { - cc grpc.ClientConnInterface -} - -func NewCommServerClient(cc grpc.ClientConnInterface) CommServerClient { - return &commServerClient{cc} -} - -func (c *commServerClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*CommendResponse, error) { - out := new(CommendResponse) - err := c.cc.Invoke(ctx, "/CommServer/Get", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *commServerClient) Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*CommendResponse, error) { - out := new(CommendResponse) - err := c.cc.Invoke(ctx, "/CommServer/Set", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// CommServerServer is the server API for CommServer service. -type CommServerServer interface { - Get(context.Context, *GetRequest) (*CommendResponse, error) - Set(context.Context, *SetRequest) (*CommendResponse, error) -} - -// UnimplementedCommServerServer can be embedded to have forward compatible implementations. -type UnimplementedCommServerServer struct { -} - -func (*UnimplementedCommServerServer) Get(context.Context, *GetRequest) (*CommendResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") -} -func (*UnimplementedCommServerServer) Set(context.Context, *SetRequest) (*CommendResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Set not implemented") -} - -func RegisterCommServerServer(s *grpc.Server, srv CommServerServer) { - s.RegisterService(&_CommServer_serviceDesc, srv) -} - -func _CommServer_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CommServerServer).Get(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/CommServer/Get", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CommServerServer).Get(ctx, req.(*GetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _CommServer_Set_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CommServerServer).Set(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/CommServer/Set", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CommServerServer).Set(ctx, req.(*SetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _CommServer_serviceDesc = grpc.ServiceDesc{ - ServiceName: "CommServer", - HandlerType: (*CommServerServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Get", - Handler: _CommServer_Get_Handler, - }, - { - MethodName: "Set", - Handler: _CommServer_Set_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "storage.proto", -} diff --git a/pkg/proto/stringx.pb.go b/pkg/proto/stringx.pb.go deleted file mode 100644 index b9dad31..0000000 --- a/pkg/proto/stringx.pb.go +++ /dev/null @@ -1,355 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.3 -// source: stringx.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 SetRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *SetRequest) Reset() { - *x = SetRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_stringx_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *SetRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SetRequest) ProtoMessage() {} - -func (x *SetRequest) ProtoReflect() protoreflect.Message { - mi := &file_stringx_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 SetRequest.ProtoReflect.Descriptor instead. -func (*SetRequest) Descriptor() ([]byte, []int) { - return file_stringx_proto_rawDescGZIP(), []int{0} -} - -func (x *SetRequest) GetKey() *BaseKey { - if x != nil { - return x.Key - } - return nil -} - -func (x *SetRequest) GetValue() string { - if x != nil { - return x.Value - } - return "" -} - -type GetRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` -} - -func (x *GetRequest) Reset() { - *x = GetRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_stringx_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetRequest) ProtoMessage() {} - -func (x *GetRequest) ProtoReflect() protoreflect.Message { - mi := &file_stringx_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 GetRequest.ProtoReflect.Descriptor instead. -func (*GetRequest) Descriptor() ([]byte, []int) { - return file_stringx_proto_rawDescGZIP(), []int{1} -} - -func (x *GetRequest) GetKey() *BaseKey { - if x != nil { - return x.Key - } - return nil -} - -type AddRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *AddRequest) Reset() { - *x = AddRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_stringx_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AddRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AddRequest) ProtoMessage() {} - -func (x *AddRequest) ProtoReflect() protoreflect.Message { - mi := &file_stringx_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 AddRequest.ProtoReflect.Descriptor instead. -func (*AddRequest) Descriptor() ([]byte, []int) { - return file_stringx_proto_rawDescGZIP(), []int{2} -} - -func (x *AddRequest) GetKey() *BaseKey { - if x != nil { - return x.Key - } - return nil -} - -func (x *AddRequest) GetValue() int64 { - if x != nil { - return x.Value - } - return 0 -} - -type RedceRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` -} - -func (x *RedceRequest) Reset() { - *x = RedceRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_stringx_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RedceRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RedceRequest) ProtoMessage() {} - -func (x *RedceRequest) ProtoReflect() protoreflect.Message { - mi := &file_stringx_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 RedceRequest.ProtoReflect.Descriptor instead. -func (*RedceRequest) Descriptor() ([]byte, []int) { - return file_stringx_proto_rawDescGZIP(), []int{3} -} - -func (x *RedceRequest) GetKey() *BaseKey { - if x != nil { - return x.Key - } - return nil -} - -var File_stringx_proto protoreflect.FileDescriptor - -var file_stringx_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x0a, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3e, 0x0a, 0x0a, 0x53, - 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, - 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, 0x22, 0x28, 0x0a, 0x0a, 0x47, - 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x3e, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x2a, 0x0a, 0x0c, 0x52, 0x65, 0x64, 0x63, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, - 0x79, 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_stringx_proto_rawDescOnce sync.Once - file_stringx_proto_rawDescData = file_stringx_proto_rawDesc -) - -func file_stringx_proto_rawDescGZIP() []byte { - file_stringx_proto_rawDescOnce.Do(func() { - file_stringx_proto_rawDescData = protoimpl.X.CompressGZIP(file_stringx_proto_rawDescData) - }) - return file_stringx_proto_rawDescData -} - -var file_stringx_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_stringx_proto_goTypes = []interface{}{ - (*SetRequest)(nil), // 0: SetRequest - (*GetRequest)(nil), // 1: GetRequest - (*AddRequest)(nil), // 2: AddRequest - (*RedceRequest)(nil), // 3: RedceRequest - (*BaseKey)(nil), // 4: BaseKey -} -var file_stringx_proto_depIdxs = []int32{ - 4, // 0: SetRequest.key:type_name -> BaseKey - 4, // 1: GetRequest.key:type_name -> BaseKey - 4, // 2: AddRequest.key:type_name -> BaseKey - 4, // 3: RedceRequest.key:type_name -> BaseKey - 4, // [4:4] is the sub-list for method output_type - 4, // [4:4] 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_stringx_proto_init() } -func file_stringx_proto_init() { - if File_stringx_proto != nil { - return - } - file_base_proto_init() - if !protoimpl.UnsafeEnabled { - file_stringx_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SetRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stringx_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stringx_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AddRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_stringx_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RedceRequest); 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_stringx_proto_rawDesc, - NumEnums: 0, - NumMessages: 4, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_stringx_proto_goTypes, - DependencyIndexes: file_stringx_proto_depIdxs, - MessageInfos: file_stringx_proto_msgTypes, - }.Build() - File_stringx_proto = out.File - file_stringx_proto_rawDesc = nil - file_stringx_proto_goTypes = nil - file_stringx_proto_depIdxs = nil -} diff --git a/pkg/structure/define.go b/pkg/structure/define.go index 0f37810..d0d30e7 100644 --- a/pkg/structure/define.go +++ b/pkg/structure/define.go @@ -1,27 +1,3 @@ package structure -type KeyBase struct { -} -func (k *KeyBase) SizeByte() int64 { - panic("not implemented") // TODO: Implement -} - -// TODO RollBack 事务相关, V2 实现 -func (k *KeyBase) RollBack() error { - panic("not implemented") // TODO: Implement -} - -// Begin 事务相关, V2 实现 -func (k *KeyBase) Begin() error { - panic("not implemented") // TODO: Implement -} - -// Comment 事务相关, V2 实现 -func (k *KeyBase) Comment() error { - panic("not implemented") // TODO: Implement -} - -func (k *KeyBase) Encode() ([]byte, error) { - panic("not implemented") // TODO: Implement -} diff --git a/protobuf/base.proto b/protobuf/base.proto index 451bcb2..4d0fd56 100644 --- a/protobuf/base.proto +++ b/protobuf/base.proto @@ -6,5 +6,5 @@ import "google/protobuf/timestamp.proto"; message BaseKey { string key = 1; int64 ttl = 2; - google.protobuf.Timestamp expire = 3; + google.protobuf.Timestamp expire = 3; } \ No newline at end of file diff --git a/protobuf/listx.proto b/protobuf/listx.proto deleted file mode 100644 index 4305a13..0000000 --- a/protobuf/listx.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; -import "base.proto"; -option go_package = "pkg/proto"; - -message SetRequest { - BaseKey key = 1; -} \ No newline at end of file diff --git a/protobuf/storage.proto b/protobuf/storage.proto deleted file mode 100644 index 634266f..0000000 --- a/protobuf/storage.proto +++ /dev/null @@ -1,23 +0,0 @@ -// Code generated by gen-struct. DO NOT EDIT. -// make gen-protobuf generated - -syntax = "proto3"; - -option go_package = "pkg/proto"; - -import "stringx.proto"; -import "listx.proto"; - -message CommendResponse { - repeated string result = 1; -} - -service CommServer { - rpc Set (SetRequest) returns (CommendResponse); - rpc Get (GetRequest) returns (CommendResponse); - rpc Add (AddRequest) returns (CommendResponse); - rpc Reduce (ReduceRequest) returns (CommendResponse); - rpc Setbit (SetbitRequest) returns (CommendResponse); - rpc Getbit (GetbitRequest) returns (CommendResponse); - rpc Set (SetRequest) returns (CommendResponse); -} \ No newline at end of file diff --git a/protobuf/stringx.proto b/protobuf/stringx.proto deleted file mode 100644 index f6ac035..0000000 --- a/protobuf/stringx.proto +++ /dev/null @@ -1,28 +0,0 @@ -syntax = "proto3"; -import "base.proto"; -option go_package = "pkg/proto"; - -message SetRequest { - BaseKey key = 1; - string value = 2; -} - -message GetRequest { - BaseKey key = 1; -} - -message AddRequest { - BaseKey key = 1; -} - -message ReduceRequest { - BaseKey key = 1; -} - -message SetbitRequest { - BaseKey key = 1; -} - -message GetbitRequest { - BaseKey key = 1; -} From e3acfcd0feb2839a4e234e557d79821203333728 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 21 Sep 2021 19:37:53 +0800 Subject: [PATCH 2/5] refactor(proto-structure): update shell --- makefile | 2 ++ shell/gen_protobuf.py | 38 +++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/makefile b/makefile index a27866a..ad04c6b 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,9 @@ STORAGE_PATH = $(BASE_PATH)/storage BASE_OUT = $(BASE_PATH)/bin dcgen: + @make gen-protobuf @python3 ./shell/proto.py + @make gen-struct .PHONY : build build: diff --git a/shell/gen_protobuf.py b/shell/gen_protobuf.py index 38c6359..5067550 100644 --- a/shell/gen_protobuf.py +++ b/shell/gen_protobuf.py @@ -1,6 +1,5 @@ import os -from typing import Dict, List -from jinja2 import Template + import yaml sysPath = os.getcwd() @@ -8,9 +7,11 @@ tempPath = f"{sysPath}/pkg/structure/generate" structurePath = f"{sysPath}/pkg/structure" protobufPath = f"{sysPath}/protobuf" + def to_camel(val: str) -> str: return "".join([k.capitalize() for k in val.split('_')]) + def load_conf(): conf_path = f"{tempPath}/tem.yaml" with open(conf_path, 'r', encoding='utf-8') as f: @@ -28,34 +29,36 @@ def load_conf(): '''生成对应的数据结构proto文件''' + + def mk_structure(cfg_camel): path = "protobuf" storagePath = f"{protobufPath}/storage.proto" for key, value in cfg_camel.items(): proto_path = path + '/' + key + '.proto' - if not os.path.exists(proto_path): # 如果这个文件不存在 + if not os.path.exists(proto_path): # 如果这个文件不存在 '''生成对应的数据结构proto文件''' - file = open(proto_path,'w') + file = open(proto_path, 'w') file.write('syntax = "proto3";\nimport "base.proto";\noption go_package = "pkg/proto";\n') for v in value: - file.write('\nmessage ' + v +'Request '+'{\n BaseKey key = 1;\n}') + file.write('\nmessage ' + v + 'Request ' + '{\n BaseKey key = 1;\n}\n') file.close() else: # 如果这个文件存在 '''更新数据结构proto文件''' with open(proto_path) as f: - line = f.readlines() + line = f.readlines() f.close() for v in value: function = v + 'Request' flag = 0 for l in line: if function in l: - flag=1 + flag = 1 break if flag == 0: - file = open(proto_path,'a') - file.write('\nmessage ' + v +'Request '+'{\n BaseKey key = 1;\n}') + file = open(proto_path, 'a') + file.write('\nmessage ' + v + 'Request ' + '{\n BaseKey key = 1;\n}\n') file.close() flag = 0 @@ -64,14 +67,15 @@ def mk_structure(cfg_camel): def mk_storage(cfg_camel): storagePath = f"{protobufPath}/storage.proto" - file = open(storagePath,'w') - file.write('// Code generated by gen-struct. DO NOT EDIT.\n// make gen-protobuf generated\n\nsyntax = "proto3";\n\noption go_package = "pkg/proto";\n\n') - for key,value in cfg_camel.items(): - file.write('import "'+ key +'.proto";\n') + file = open(storagePath, 'w') + file.write( + '// Code generated by gen-struct. DO NOT EDIT.\n// make gen-protobuf generated\n\nsyntax = "proto3";\n\noption go_package = "pkg/proto";\n\n') + for key, value in cfg_camel.items(): + file.write('import "' + key + '.proto";\n') file.write('\nmessage CommendResponse {\n repeated string result = 1;\n}\n\nservice CommServer {\n') - for key,value in cfg_camel.items(): + for key, value in cfg_camel.items(): for v in value: - file.write(' rpc '+ v +' ('+ v +'Request) returns (CommendResponse);\n') + file.write(' rpc ' + v + ' (' + v + 'Request) returns (CommendResponse);\n') file.write('}') file.close() print("storage.proto", "-> success") @@ -81,7 +85,3 @@ if __name__ == "__main__": conf, cfg_camel = load_conf() mk_structure(cfg_camel) # 生成对应的数据结构proto文件 mk_storage(cfg_camel) - - - - From ddd7a8a5edd4d291d8262e14f1ad4f6c70d5084f Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 21 Sep 2021 20:16:08 +0800 Subject: [PATCH 3/5] refactor(structure, shell): update shell, structure --- pkg/structure/generate/tem.yaml | 5 +- pkg/structure/stringx/option.go | 14 ---- pkg/structure/stringx/string.go | 3 - shell/gen_protobuf.py | 2 +- shell/gen_struct_interface.py | 109 -------------------------------- shell/make-struct.py | 8 +-- 6 files changed, 6 insertions(+), 135 deletions(-) delete mode 100644 shell/gen_struct_interface.py diff --git a/pkg/structure/generate/tem.yaml b/pkg/structure/generate/tem.yaml index b81c1bf..9aae05e 100644 --- a/pkg/structure/generate/tem.yaml +++ b/pkg/structure/generate/tem.yaml @@ -6,7 +6,4 @@ STRING_X: - add - reduce - setbit - - getbit - -LIST_X: - - set \ No newline at end of file + - getbit \ No newline at end of file diff --git a/pkg/structure/stringx/option.go b/pkg/structure/stringx/option.go index f6c7490..653ddc2 100644 --- a/pkg/structure/stringx/option.go +++ b/pkg/structure/stringx/option.go @@ -1,15 +1 @@ package stringx - -import "gitee.com/timedb/wheatCache/pkg/proto" - -func (s *StringX) Set(req *proto.SetRequest) ([]string, error) { - s.Value = req.Value - return nil, nil -} - -func (s *StringX) Get(req *proto.GetRequest) ([]string, error) { - result := make([]string, 0, 1) - result = append(result, s.Value) - - return result, nil -} diff --git a/pkg/structure/stringx/string.go b/pkg/structure/stringx/string.go index a5f4e71..5e9740c 100644 --- a/pkg/structure/stringx/string.go +++ b/pkg/structure/stringx/string.go @@ -1,8 +1,5 @@ package stringx -import "gitee.com/timedb/wheatCache/pkg/structure" - type StringX struct { - structure.KeyBase Value string } diff --git a/shell/gen_protobuf.py b/shell/gen_protobuf.py index 5067550..2ca11a2 100644 --- a/shell/gen_protobuf.py +++ b/shell/gen_protobuf.py @@ -17,7 +17,7 @@ def load_conf(): with open(conf_path, 'r', encoding='utf-8') as f: cfg = f.read() - cfg = yaml.load(cfg) + cfg = yaml.load(cfg, Loader=yaml.FullLoader) cfg_camel = {} diff --git a/shell/gen_struct_interface.py b/shell/gen_struct_interface.py deleted file mode 100644 index 4e22bfd..0000000 --- a/shell/gen_struct_interface.py +++ /dev/null @@ -1,109 +0,0 @@ -import os - - -def DealList(li: list): - # 对列表进行处理 - flag = 0 - InterName = [] - BlankNum = [] - SliceNum = [] - for i in range(len(li)): - if flag == 0: - SliceNum.append(i) - InterName.append(f"{li[i].lower().title()}Interface".replace("_", "").replace(":", "")) - flag = 1 - if li[i] == '': - BlankNum.append(i) - flag = 0 - Dict = {} - for i in range(len(InterName)-1): - Dict[InterName[i]] = li[SliceNum[i]+1:BlankNum[i]] - Dict[InterName[-1]] = li[BlankNum[-1]+2:] - return Dict - - -def SetInterface(): - # 对读取到的yaml进行处理 - Temp = [] - path = os.getcwd() - WirtePath = f"{path}/pkg/structure/interface.go" - ReadPath = f"{path}/pkg/structure/generate/tem.yaml" - with open(ReadPath, "r") as f: - title = f.read() - title = title.split("\n")[2:] - for i in title: - if ' - ' not in i: - Temp.append(i) - if ' - ' in i: - i = i.split("-")[1] - Temp.append(i) - - # 对列表进行处理,便于自动补全 - dic = DealList(Temp) - - # 通过传入的列表对interface.go进行自动补全 - Temp = [] - AppendList = [] - with open(WirtePath, "r") as f: - context = f.read() - context = context.split("\n") - flag = 0 - for i in context: - if "interface" in i: - flag = 1 # 开锁 - if "}" in i: - Temp.append(i) - AppendList.append(Temp) - Temp = [] - flag = 0 # 上锁 - if flag == 1: - Temp.append(i) - - # 拆分成功, 开始匹配 - Del = [] - res = context[0:20] - for i in AppendList[2:]: - x = i[0:2] - for key, values in dic.items(): - if key in i[0]: - Del.append(key) - for val in values: - x.append(f'\t{val.title().lstrip()}(*pr' - f'oto.{val.title().lstrip()}Request) ([]string, error)'.replace("_", "")) - x.append("\n}\n\n") - for j in x: - res.append(j) - for i in Del: - dic.pop(i) - # 添加新增的 - for key, values in dic.items(): - w = [] - w.append(f"type {key} interface" + "{") - w.append('\tKeyBaseInterface') - for val in values: - w.append(f'\t{val.title().lstrip()}(*pr' - f'oto.{val.title().lstrip()}Request) ([]string, error)'.replace("_", "")) - w.append("\n}\n\n") - for j in w: - res.append(j) - f = open(WirtePath, 'w') - judge = "" - for i in res: - if judge == i: - continue - judge = i - if "package" in i: - i = f"{i}\n" - if "import" in i: - i = f"{i}\n" - if i == '': - i = '\n' - if i == '}' or i == '\n{\n': - i = '\n}\n' - i = i.replace('\t', '\n\t') - f.write(i) - f.close() - - -if __name__ == "__main__": - SetInterface() \ No newline at end of file diff --git a/shell/make-struct.py b/shell/make-struct.py index 994c094..64aa538 100644 --- a/shell/make-struct.py +++ b/shell/make-struct.py @@ -1,6 +1,7 @@ import os -from jinja2 import Template + import yaml +from jinja2 import Template sysPath = os.getcwd() tempPath = f"{sysPath}/pkg/structure/generate" @@ -29,15 +30,13 @@ def load_conf(): with open(conf_path, 'r', encoding='utf-8') as f: cfg = f.read() - cfg = yaml.load(cfg) + cfg = yaml.load(cfg, Loader=yaml.FullLoader) cfg_camel = {} for key, val in cfg.items(): cfg_camel[key] = [to_camel(v) for v in val] - print(cfg_camel) - return cfg, cfg_camel @@ -60,6 +59,7 @@ def set_structure_const_template(conf: dict): with open(temp_path, 'w', encoding='utf-8') as f: f.write(text) + # 生成接口 From a9ab92c16a98ca5c68ce6eeffc7e6cc357f62cd3 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 21 Sep 2021 20:59:19 +0800 Subject: [PATCH 4/5] refactor(structure): refactor struct interface gen --- go.mod | 1 - go.sum | 3 +- pkg/proto/base.pb.go | 166 +++++++++ pkg/proto/storage.pb.go | 445 +++++++++++++++++++++++ pkg/proto/stringx.pb.go | 464 ++++++++++++++++++++++++ pkg/structure/generate/structure.gen.go | 21 +- pkg/structure/interface.gen.go | 29 ++ pkg/structure/stringx/string.go | 46 +++ protobuf/storage.proto | 21 ++ protobuf/stringx.proto | 27 ++ shell/make-struct.py | 14 +- 11 files changed, 1220 insertions(+), 17 deletions(-) create mode 100644 pkg/proto/base.pb.go create mode 100644 pkg/proto/storage.pb.go create mode 100644 pkg/proto/stringx.pb.go create mode 100644 pkg/structure/interface.gen.go create mode 100644 protobuf/storage.proto create mode 100644 protobuf/stringx.proto diff --git a/go.mod b/go.mod index 8dd54cf..75777b2 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 github.com/stretchr/testify v1.7.0 - golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect google.golang.org/grpc v1.38.0 google.golang.org/protobuf v1.26.0 ) diff --git a/go.sum b/go.sum index 4cb7eeb..795c424 100644 --- a/go.sum +++ b/go.sum @@ -397,9 +397,8 @@ golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg= -golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/pkg/proto/base.pb.go b/pkg/proto/base.pb.go new file mode 100644 index 0000000..7e14747 --- /dev/null +++ b/pkg/proto/base.pb.go @@ -0,0 +1,166 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.17.3 +// source: base.proto + +package proto + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + 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 BaseKey struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Ttl int64 `protobuf:"varint,2,opt,name=ttl,proto3" json:"ttl,omitempty"` + Expire *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=expire,proto3" json:"expire,omitempty"` +} + +func (x *BaseKey) Reset() { + *x = BaseKey{} + if protoimpl.UnsafeEnabled { + mi := &file_base_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BaseKey) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BaseKey) ProtoMessage() {} + +func (x *BaseKey) ProtoReflect() protoreflect.Message { + mi := &file_base_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 BaseKey.ProtoReflect.Descriptor instead. +func (*BaseKey) Descriptor() ([]byte, []int) { + return file_base_proto_rawDescGZIP(), []int{0} +} + +func (x *BaseKey) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *BaseKey) GetTtl() int64 { + if x != nil { + return x.Ttl + } + return 0 +} + +func (x *BaseKey) GetExpire() *timestamppb.Timestamp { + if x != nil { + return x.Expire + } + return nil +} + +var File_base_proto protoreflect.FileDescriptor + +var file_base_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x61, 0x0a, + 0x07, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x74, + 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x74, 0x74, 0x6c, 0x12, 0x32, 0x0a, 0x06, + 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x06, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, + 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_base_proto_rawDescOnce sync.Once + file_base_proto_rawDescData = file_base_proto_rawDesc +) + +func file_base_proto_rawDescGZIP() []byte { + file_base_proto_rawDescOnce.Do(func() { + file_base_proto_rawDescData = protoimpl.X.CompressGZIP(file_base_proto_rawDescData) + }) + return file_base_proto_rawDescData +} + +var file_base_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_base_proto_goTypes = []interface{}{ + (*BaseKey)(nil), // 0: BaseKey + (*timestamppb.Timestamp)(nil), // 1: google.protobuf.Timestamp +} +var file_base_proto_depIdxs = []int32{ + 1, // 0: BaseKey.expire:type_name -> google.protobuf.Timestamp + 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 +} + +func init() { file_base_proto_init() } +func file_base_proto_init() { + if File_base_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_base_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BaseKey); 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_base_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_base_proto_goTypes, + DependencyIndexes: file_base_proto_depIdxs, + MessageInfos: file_base_proto_msgTypes, + }.Build() + File_base_proto = out.File + file_base_proto_rawDesc = nil + file_base_proto_goTypes = nil + file_base_proto_depIdxs = nil +} diff --git a/pkg/proto/storage.pb.go b/pkg/proto/storage.pb.go new file mode 100644 index 0000000..45396a4 --- /dev/null +++ b/pkg/proto/storage.pb.go @@ -0,0 +1,445 @@ +// Code generated by gen-struct. DO NOT EDIT. +// make gen-protobuf generated + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.17.3 +// source: storage.proto + +package proto + +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 CommendResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result []string `protobuf:"bytes,1,rep,name=result,proto3" json:"result,omitempty"` +} + +func (x *CommendResponse) Reset() { + *x = CommendResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_storage_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CommendResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CommendResponse) ProtoMessage() {} + +func (x *CommendResponse) ProtoReflect() protoreflect.Message { + mi := &file_storage_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 CommendResponse.ProtoReflect.Descriptor instead. +func (*CommendResponse) Descriptor() ([]byte, []int) { + return file_storage_proto_rawDescGZIP(), []int{0} +} + +func (x *CommendResponse) GetResult() []string { + if x != nil { + return x.Result + } + return nil +} + +var File_storage_proto protoreflect.FileDescriptor + +var file_storage_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x0d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x29, + 0x0a, 0x0f, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0x82, 0x02, 0x0a, 0x0a, 0x43, 0x6f, + 0x6d, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x24, 0x0a, 0x03, 0x53, 0x65, 0x74, 0x12, + 0x0b, 0x2e, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x43, + 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, + 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x0b, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x03, 0x41, 0x64, 0x64, 0x12, 0x0b, 0x2e, 0x41, 0x64, + 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x52, 0x65, + 0x64, 0x75, 0x63, 0x65, 0x12, 0x0e, 0x2e, 0x52, 0x65, 0x64, 0x75, 0x63, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x53, 0x65, 0x74, 0x62, 0x69, 0x74, + 0x12, 0x0e, 0x2e, 0x53, 0x65, 0x74, 0x62, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x10, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x47, 0x65, 0x74, 0x62, 0x69, 0x74, 0x12, 0x0e, 0x2e, 0x47, + 0x65, 0x74, 0x62, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x43, + 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0b, + 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_storage_proto_rawDescOnce sync.Once + file_storage_proto_rawDescData = file_storage_proto_rawDesc +) + +func file_storage_proto_rawDescGZIP() []byte { + file_storage_proto_rawDescOnce.Do(func() { + file_storage_proto_rawDescData = protoimpl.X.CompressGZIP(file_storage_proto_rawDescData) + }) + return file_storage_proto_rawDescData +} + +var file_storage_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_storage_proto_goTypes = []interface{}{ + (*CommendResponse)(nil), // 0: CommendResponse + (*SetRequest)(nil), // 1: SetRequest + (*GetRequest)(nil), // 2: GetRequest + (*AddRequest)(nil), // 3: AddRequest + (*ReduceRequest)(nil), // 4: ReduceRequest + (*SetbitRequest)(nil), // 5: SetbitRequest + (*GetbitRequest)(nil), // 6: GetbitRequest +} +var file_storage_proto_depIdxs = []int32{ + 1, // 0: CommServer.Set:input_type -> SetRequest + 2, // 1: CommServer.Get:input_type -> GetRequest + 3, // 2: CommServer.Add:input_type -> AddRequest + 4, // 3: CommServer.Reduce:input_type -> ReduceRequest + 5, // 4: CommServer.Setbit:input_type -> SetbitRequest + 6, // 5: CommServer.Getbit:input_type -> GetbitRequest + 0, // 6: CommServer.Set:output_type -> CommendResponse + 0, // 7: CommServer.Get:output_type -> CommendResponse + 0, // 8: CommServer.Add:output_type -> CommendResponse + 0, // 9: CommServer.Reduce:output_type -> CommendResponse + 0, // 10: CommServer.Setbit:output_type -> CommendResponse + 0, // 11: CommServer.Getbit:output_type -> CommendResponse + 6, // [6:12] is the sub-list for method output_type + 0, // [0:6] 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_storage_proto_init() } +func file_storage_proto_init() { + if File_storage_proto != nil { + return + } + file_stringx_proto_init() + if !protoimpl.UnsafeEnabled { + file_storage_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CommendResponse); 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_storage_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_storage_proto_goTypes, + DependencyIndexes: file_storage_proto_depIdxs, + MessageInfos: file_storage_proto_msgTypes, + }.Build() + File_storage_proto = out.File + file_storage_proto_rawDesc = nil + file_storage_proto_goTypes = nil + file_storage_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 + +// CommServerClient is the client API for CommServer service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type CommServerClient interface { + Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*CommendResponse, error) + Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*CommendResponse, error) + Add(ctx context.Context, in *AddRequest, opts ...grpc.CallOption) (*CommendResponse, error) + Reduce(ctx context.Context, in *ReduceRequest, opts ...grpc.CallOption) (*CommendResponse, error) + Setbit(ctx context.Context, in *SetbitRequest, opts ...grpc.CallOption) (*CommendResponse, error) + Getbit(ctx context.Context, in *GetbitRequest, opts ...grpc.CallOption) (*CommendResponse, error) +} + +type commServerClient struct { + cc grpc.ClientConnInterface +} + +func NewCommServerClient(cc grpc.ClientConnInterface) CommServerClient { + return &commServerClient{cc} +} + +func (c *commServerClient) Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*CommendResponse, error) { + out := new(CommendResponse) + err := c.cc.Invoke(ctx, "/CommServer/Set", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commServerClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*CommendResponse, error) { + out := new(CommendResponse) + err := c.cc.Invoke(ctx, "/CommServer/Get", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commServerClient) Add(ctx context.Context, in *AddRequest, opts ...grpc.CallOption) (*CommendResponse, error) { + out := new(CommendResponse) + err := c.cc.Invoke(ctx, "/CommServer/Add", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commServerClient) Reduce(ctx context.Context, in *ReduceRequest, opts ...grpc.CallOption) (*CommendResponse, error) { + out := new(CommendResponse) + err := c.cc.Invoke(ctx, "/CommServer/Reduce", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commServerClient) Setbit(ctx context.Context, in *SetbitRequest, opts ...grpc.CallOption) (*CommendResponse, error) { + out := new(CommendResponse) + err := c.cc.Invoke(ctx, "/CommServer/Setbit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commServerClient) Getbit(ctx context.Context, in *GetbitRequest, opts ...grpc.CallOption) (*CommendResponse, error) { + out := new(CommendResponse) + err := c.cc.Invoke(ctx, "/CommServer/Getbit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// CommServerServer is the server API for CommServer service. +type CommServerServer interface { + Set(context.Context, *SetRequest) (*CommendResponse, error) + Get(context.Context, *GetRequest) (*CommendResponse, error) + Add(context.Context, *AddRequest) (*CommendResponse, error) + Reduce(context.Context, *ReduceRequest) (*CommendResponse, error) + Setbit(context.Context, *SetbitRequest) (*CommendResponse, error) + Getbit(context.Context, *GetbitRequest) (*CommendResponse, error) +} + +// UnimplementedCommServerServer can be embedded to have forward compatible implementations. +type UnimplementedCommServerServer struct { +} + +func (*UnimplementedCommServerServer) Set(context.Context, *SetRequest) (*CommendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Set not implemented") +} +func (*UnimplementedCommServerServer) Get(context.Context, *GetRequest) (*CommendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") +} +func (*UnimplementedCommServerServer) Add(context.Context, *AddRequest) (*CommendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Add not implemented") +} +func (*UnimplementedCommServerServer) Reduce(context.Context, *ReduceRequest) (*CommendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Reduce not implemented") +} +func (*UnimplementedCommServerServer) Setbit(context.Context, *SetbitRequest) (*CommendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Setbit not implemented") +} +func (*UnimplementedCommServerServer) Getbit(context.Context, *GetbitRequest) (*CommendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Getbit not implemented") +} + +func RegisterCommServerServer(s *grpc.Server, srv CommServerServer) { + s.RegisterService(&_CommServer_serviceDesc, srv) +} + +func _CommServer_Set_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommServerServer).Set(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/CommServer/Set", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommServerServer).Set(ctx, req.(*SetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _CommServer_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommServerServer).Get(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/CommServer/Get", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommServerServer).Get(ctx, req.(*GetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _CommServer_Add_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommServerServer).Add(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/CommServer/Add", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommServerServer).Add(ctx, req.(*AddRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _CommServer_Reduce_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReduceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommServerServer).Reduce(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/CommServer/Reduce", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommServerServer).Reduce(ctx, req.(*ReduceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _CommServer_Setbit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetbitRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommServerServer).Setbit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/CommServer/Setbit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommServerServer).Setbit(ctx, req.(*SetbitRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _CommServer_Getbit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetbitRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommServerServer).Getbit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/CommServer/Getbit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommServerServer).Getbit(ctx, req.(*GetbitRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _CommServer_serviceDesc = grpc.ServiceDesc{ + ServiceName: "CommServer", + HandlerType: (*CommServerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Set", + Handler: _CommServer_Set_Handler, + }, + { + MethodName: "Get", + Handler: _CommServer_Get_Handler, + }, + { + MethodName: "Add", + Handler: _CommServer_Add_Handler, + }, + { + MethodName: "Reduce", + Handler: _CommServer_Reduce_Handler, + }, + { + MethodName: "Setbit", + Handler: _CommServer_Setbit_Handler, + }, + { + MethodName: "Getbit", + Handler: _CommServer_Getbit_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "storage.proto", +} diff --git a/pkg/proto/stringx.pb.go b/pkg/proto/stringx.pb.go new file mode 100644 index 0000000..58c2e40 --- /dev/null +++ b/pkg/proto/stringx.pb.go @@ -0,0 +1,464 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.17.3 +// source: stringx.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 SetRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *SetRequest) Reset() { + *x = SetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetRequest) ProtoMessage() {} + +func (x *SetRequest) ProtoReflect() protoreflect.Message { + mi := &file_stringx_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 SetRequest.ProtoReflect.Descriptor instead. +func (*SetRequest) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{0} +} + +func (x *SetRequest) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +type GetRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *GetRequest) Reset() { + *x = GetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetRequest) ProtoMessage() {} + +func (x *GetRequest) ProtoReflect() protoreflect.Message { + mi := &file_stringx_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 GetRequest.ProtoReflect.Descriptor instead. +func (*GetRequest) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{1} +} + +func (x *GetRequest) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +type AddRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *AddRequest) Reset() { + *x = AddRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AddRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddRequest) ProtoMessage() {} + +func (x *AddRequest) ProtoReflect() protoreflect.Message { + mi := &file_stringx_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 AddRequest.ProtoReflect.Descriptor instead. +func (*AddRequest) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{2} +} + +func (x *AddRequest) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +type ReduceRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *ReduceRequest) Reset() { + *x = ReduceRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReduceRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReduceRequest) ProtoMessage() {} + +func (x *ReduceRequest) ProtoReflect() protoreflect.Message { + mi := &file_stringx_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 ReduceRequest.ProtoReflect.Descriptor instead. +func (*ReduceRequest) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{3} +} + +func (x *ReduceRequest) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +type SetbitRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *SetbitRequest) Reset() { + *x = SetbitRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SetbitRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetbitRequest) ProtoMessage() {} + +func (x *SetbitRequest) ProtoReflect() protoreflect.Message { + mi := &file_stringx_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 SetbitRequest.ProtoReflect.Descriptor instead. +func (*SetbitRequest) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{4} +} + +func (x *SetbitRequest) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +type GetbitRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *GetbitRequest) Reset() { + *x = GetbitRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetbitRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetbitRequest) ProtoMessage() {} + +func (x *GetbitRequest) ProtoReflect() protoreflect.Message { + mi := &file_stringx_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 GetbitRequest.ProtoReflect.Descriptor instead. +func (*GetbitRequest) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{5} +} + +func (x *GetbitRequest) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +var File_stringx_proto protoreflect.FileDescriptor + +var file_stringx_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x0a, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x28, 0x0a, 0x0a, 0x53, + 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x28, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, + 0x28, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, + 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x2b, 0x0a, 0x0d, 0x52, 0x65, 0x64, + 0x75, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, + 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x2b, 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x62, 0x69, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x22, 0x2b, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x62, 0x69, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stringx_proto_rawDescOnce sync.Once + file_stringx_proto_rawDescData = file_stringx_proto_rawDesc +) + +func file_stringx_proto_rawDescGZIP() []byte { + file_stringx_proto_rawDescOnce.Do(func() { + file_stringx_proto_rawDescData = protoimpl.X.CompressGZIP(file_stringx_proto_rawDescData) + }) + return file_stringx_proto_rawDescData +} + +var file_stringx_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_stringx_proto_goTypes = []interface{}{ + (*SetRequest)(nil), // 0: SetRequest + (*GetRequest)(nil), // 1: GetRequest + (*AddRequest)(nil), // 2: AddRequest + (*ReduceRequest)(nil), // 3: ReduceRequest + (*SetbitRequest)(nil), // 4: SetbitRequest + (*GetbitRequest)(nil), // 5: GetbitRequest + (*BaseKey)(nil), // 6: BaseKey +} +var file_stringx_proto_depIdxs = []int32{ + 6, // 0: SetRequest.key:type_name -> BaseKey + 6, // 1: GetRequest.key:type_name -> BaseKey + 6, // 2: AddRequest.key:type_name -> BaseKey + 6, // 3: ReduceRequest.key:type_name -> BaseKey + 6, // 4: SetbitRequest.key:type_name -> BaseKey + 6, // 5: GetbitRequest.key:type_name -> BaseKey + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_stringx_proto_init() } +func file_stringx_proto_init() { + if File_stringx_proto != nil { + return + } + file_base_proto_init() + if !protoimpl.UnsafeEnabled { + file_stringx_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stringx_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stringx_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AddRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stringx_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReduceRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stringx_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetbitRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stringx_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetbitRequest); 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_stringx_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_stringx_proto_goTypes, + DependencyIndexes: file_stringx_proto_depIdxs, + MessageInfos: file_stringx_proto_msgTypes, + }.Build() + File_stringx_proto = out.File + file_stringx_proto_rawDesc = nil + file_stringx_proto_goTypes = nil + file_stringx_proto_depIdxs = nil +} diff --git a/pkg/structure/generate/structure.gen.go b/pkg/structure/generate/structure.gen.go index 9931336..e9dc9d5 100644 --- a/pkg/structure/generate/structure.gen.go +++ b/pkg/structure/generate/structure.gen.go @@ -9,30 +9,27 @@ const ( ) const ( - DEFAULT_COMM = iota - SET + DEFAULT_COMM = iota + SET GET ADD REDUCE SETBIT GETBIT - ) -var CommKeyString = map[string]int {"set": STRING_X, - "get": STRING_X, - "add": STRING_X, +var CommKeyString = map[string]int{"set": STRING_X, + "get": STRING_X, + "add": STRING_X, "reduce": STRING_X, "setbit": STRING_X, "getbit": STRING_X, - } -var CommKey = map[int]int {SET: STRING_X, - GET: STRING_X, - ADD: STRING_X, +var CommKey = map[int]int{SET: STRING_X, + GET: STRING_X, + ADD: STRING_X, REDUCE: STRING_X, SETBIT: STRING_X, GETBIT: STRING_X, - -} \ No newline at end of file +} diff --git a/pkg/structure/interface.gen.go b/pkg/structure/interface.gen.go new file mode 100644 index 0000000..ba53360 --- /dev/null +++ b/pkg/structure/interface.gen.go @@ -0,0 +1,29 @@ +// Code generated by gen-struct-const. DO NOT EDIT. +// make gen-struct generated + +package structure + +import "gitee.com/timedb/wheatCache/pkg/proto" + +type KeyBaseInterface interface { + SizeByte() int64 + + // TODO RollBack 事务相关, V2 实现 + RollBack() error + // Begin 事务相关, V2 实现 + Begin() error + // Comment 事务相关, V2 实现 + Comment() error + + Encode() ([]byte, error) +} + +type StringXInterface interface { + KeyBaseInterface + Set(*proto.SetRequest) ([]string, error) + Get(*proto.GetRequest) ([]string, error) + Add(*proto.AddRequest) ([]string, error) + Reduce(*proto.ReduceRequest) ([]string, error) + Setbit(*proto.SetbitRequest) ([]string, error) + Getbit(*proto.GetbitRequest) ([]string, error) +} diff --git a/pkg/structure/stringx/string.go b/pkg/structure/stringx/string.go index 5e9740c..7a86a05 100644 --- a/pkg/structure/stringx/string.go +++ b/pkg/structure/stringx/string.go @@ -1,5 +1,51 @@ package stringx +import "gitee.com/timedb/wheatCache/pkg/proto" + type StringX struct { Value string } + +func (s *StringX) SizeByte() int64 { + panic("implement me") +} + +func (s *StringX) RollBack() error { + panic("implement me") +} + +func (s *StringX) Begin() error { + panic("implement me") +} + +func (s *StringX) Comment() error { + panic("implement me") +} + +func (s *StringX) Encode() ([]byte, error) { + panic("implement me") +} + +func (s *StringX) Set(req *proto.SetRequest) ([]string, error) { + panic("implement me") +} + +func (s *StringX) Get(req *proto.GetRequest) ([]string, error) { + panic("implement me") +} + +func (s *StringX) Add(req *proto.AddRequest) ([]string, error) { + panic("implement me") +} + +func (s *StringX) Reduce(req *proto.ReduceRequest) ([]string, error) { + panic("implement me") +} + +func (s *StringX) Setbit(req *proto.SetbitRequest) ([]string, error) { + panic("implement me") +} + +func (s *StringX) Getbit(req *proto.GetbitRequest) ([]string, error) { + panic("implement me") +} diff --git a/protobuf/storage.proto b/protobuf/storage.proto new file mode 100644 index 0000000..d877215 --- /dev/null +++ b/protobuf/storage.proto @@ -0,0 +1,21 @@ +// Code generated by gen-struct. DO NOT EDIT. +// make gen-protobuf generated + +syntax = "proto3"; + +option go_package = "pkg/proto"; + +import "stringx.proto"; + +message CommendResponse { + repeated string result = 1; +} + +service CommServer { + rpc Set (SetRequest) returns (CommendResponse); + rpc Get (GetRequest) returns (CommendResponse); + rpc Add (AddRequest) returns (CommendResponse); + rpc Reduce (ReduceRequest) returns (CommendResponse); + rpc Setbit (SetbitRequest) returns (CommendResponse); + rpc Getbit (GetbitRequest) returns (CommendResponse); +} \ No newline at end of file diff --git a/protobuf/stringx.proto b/protobuf/stringx.proto new file mode 100644 index 0000000..3c1ca5d --- /dev/null +++ b/protobuf/stringx.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; +import "base.proto"; +option go_package = "pkg/proto"; + +message SetRequest { + BaseKey key = 1; +} + +message GetRequest { + BaseKey key = 1; +} + +message AddRequest { + BaseKey key = 1; +} + +message ReduceRequest { + BaseKey key = 1; +} + +message SetbitRequest { + BaseKey key = 1; +} + +message GetbitRequest { + BaseKey key = 1; +} diff --git a/shell/make-struct.py b/shell/make-struct.py index 64aa538..9cf7898 100644 --- a/shell/make-struct.py +++ b/shell/make-struct.py @@ -16,6 +16,10 @@ class KeyMap(object): self.upper = [v.upper() for v in val] +def go_fmt(path: str): + os.system(f"go fmt {path}") + + def to_camel(val: str) -> str: return "".join([k.capitalize() for k in val.split('_')]) @@ -61,8 +65,6 @@ def set_structure_const_template(conf: dict): # 生成接口 - - def set_structure_interface(conf): text = load_template("interface.template") Dic = {} @@ -77,7 +79,15 @@ def set_structure_interface(conf): f.write(text) +def format_code_go(): + go_fmt(f"{structurePath}/interface.gen.go") + go_fmt(f"{structurePath}/generate/structure.gen.go") + + if __name__ == "__main__": conf, cfg_camel = load_conf() set_structure_const_template(conf) set_structure_interface(cfg_camel) + + # 格式化代码 + format_code_go() From cc57179c11d9f98bdbfc9bbdcc8833980cc46ff5 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 21 Sep 2021 20:59:48 +0800 Subject: [PATCH 5/5] feat(storage): update server --- storage/server/server.go | 52 ++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/storage/server/server.go b/storage/server/server.go index 0265082..82806c3 100644 --- a/storage/server/server.go +++ b/storage/server/server.go @@ -2,10 +2,7 @@ package server import ( context "context" - "errors" - "gitee.com/timedb/wheatCache/pkg/proto" - "gitee.com/timedb/wheatCache/pkg/structure/stringx" ) type server struct { @@ -20,41 +17,28 @@ func (s *server) Get( cxt context.Context, req *proto.GetRequest, ) (*proto.CommendResponse, error) { - - var value interface{} - - switch value.(type) { - case *stringx.StringX: - default: - return nil, errors.New("awdwd") - } - - result, err := value.(*stringx.StringX).Get(req) - if err != nil { - return nil, err - } - return &proto.CommendResponse{ - Result: result, - }, nil + panic("implement me") } func (s *server) Set( ctx context.Context, req *proto.SetRequest, ) (*proto.CommendResponse, error) { - var value interface{} - - switch value.(type) { - case *stringx.StringX: - default: - return nil, errors.New("awdwd") - } - - result, err := value.(*stringx.StringX).Set(req) - if err != nil { - return nil, err - } - return &proto.CommendResponse{ - Result: result, - }, nil + panic("implement me") +} + +func (s *server) Add(ctx context.Context, request *proto.AddRequest) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Reduce(ctx context.Context, request *proto.ReduceRequest) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Setbit(ctx context.Context, request *proto.SetbitRequest) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Getbit(ctx context.Context, request *proto.GetbitRequest) (*proto.CommendResponse, error) { + panic("implement me") }