From 4405512540ec733e2e2bc044104b4d46f9703fc5 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sat, 18 Sep 2021 15:27:45 +0800 Subject: [PATCH] feat(structure-pkg): add storage pkg --- {structure => pkg}/proto/base.pb.go | 44 ++++++--- {storage => pkg}/proto/storage.pb.go | 101 +++++++++++--------- {structure => pkg}/proto/stringx.pb.go | 5 +- proto/structure/base.proto | 8 -- protobuf/base.proto | 10 ++ {proto/storage => protobuf}/storage.proto | 9 +- {proto/structure => protobuf}/stringx.proto | 3 +- shell/proto.py | 2 +- storage/server/server.go | 2 +- 9 files changed, 106 insertions(+), 78 deletions(-) rename {structure => pkg}/proto/base.pb.go (63%) rename {storage => pkg}/proto/storage.pb.go (75%) rename {structure => pkg}/proto/stringx.pb.go (97%) delete mode 100644 proto/structure/base.proto create mode 100644 protobuf/base.proto rename {proto/storage => protobuf}/storage.proto (67%) rename {proto/structure => protobuf}/stringx.proto (86%) diff --git a/structure/proto/base.pb.go b/pkg/proto/base.pb.go similarity index 63% rename from structure/proto/base.pb.go rename to pkg/proto/base.pb.go index 0553add..7e14747 100644 --- a/structure/proto/base.pb.go +++ b/pkg/proto/base.pb.go @@ -9,6 +9,7 @@ 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" ) @@ -25,8 +26,9 @@ type BaseKey struct { 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"` + 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() { @@ -75,15 +77,27 @@ func (x *BaseKey) GetTtl() int64 { 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, 0x22, 0x2d, 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, 0x42, 0x11, 0x5a, 0x0f, 0x73, - 0x74, 0x72, 0x75, 0x63, 0x74, 0x75, 0x72, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 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 ( @@ -100,14 +114,16 @@ func file_base_proto_rawDescGZIP() []byte { var file_base_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_base_proto_goTypes = []interface{}{ - (*BaseKey)(nil), // 0: BaseKey + (*BaseKey)(nil), // 0: BaseKey + (*timestamppb.Timestamp)(nil), // 1: google.protobuf.Timestamp } var file_base_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 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() } diff --git a/storage/proto/storage.pb.go b/pkg/proto/storage.pb.go similarity index 75% rename from storage/proto/storage.pb.go rename to pkg/proto/storage.pb.go index 2440907..4187ebc 100644 --- a/storage/proto/storage.pb.go +++ b/pkg/proto/storage.pb.go @@ -29,9 +29,9 @@ type Comm struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Operation string `protobuf:"bytes,2,opt,name=Operation,proto3" json:"Operation,omitempty"` - Option []string `protobuf:"bytes,3,rep,name=Option,proto3" json:"Option,omitempty"` + // Types that are assignable to CommOption: + // *Comm_StringComm + CommOption isComm_CommOption `protobuf_oneof:"comm_option"` } func (x *Comm) Reset() { @@ -66,27 +66,30 @@ func (*Comm) Descriptor() ([]byte, []int) { return file_storage_proto_rawDescGZIP(), []int{0} } -func (x *Comm) GetKey() string { - if x != nil { - return x.Key - } - return "" -} - -func (x *Comm) GetOperation() string { - if x != nil { - return x.Operation - } - return "" -} - -func (x *Comm) GetOption() []string { - if x != nil { - return x.Option +func (m *Comm) GetCommOption() isComm_CommOption { + if m != nil { + return m.CommOption } return nil } +func (x *Comm) GetStringComm() *StringxComm { + if x, ok := x.GetCommOption().(*Comm_StringComm); ok { + return x.StringComm + } + return nil +} + +type isComm_CommOption interface { + isComm_CommOption() +} + +type Comm_StringComm struct { + StringComm *StringxComm `protobuf:"bytes,1,opt,name=string_comm,json=stringComm,proto3,oneof"` +} + +func (*Comm_StringComm) isComm_CommOption() {} + type CommendRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -184,24 +187,24 @@ func (x *CommendResponse) GetResult() []string { 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, 0x22, - 0x4e, 0x0a, 0x04, 0x43, 0x6f, 0x6d, 0x6d, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x4f, 0x70, 0x65, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x4f, 0x70, - 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, - 0x33, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x21, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x52, 0x08, 0x63, 0x6f, 0x6d, 0x6d, - 0x65, 0x6e, 0x64, 0x73, 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, - 0x3a, 0x0a, 0x0a, 0x43, 0x6f, 0x6d, 0x6d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2c, 0x0a, - 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x12, 0x0f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, - 0x6e, 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, 0x42, 0x0f, 0x5a, 0x0d, 0x73, - 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 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, 0x46, + 0x0a, 0x04, 0x43, 0x6f, 0x6d, 0x6d, 0x12, 0x2f, 0x0a, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, + 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x53, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x78, 0x43, 0x6f, 0x6d, 0x6d, 0x48, 0x00, 0x52, 0x0a, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6d, 0x6d, 0x42, 0x0d, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x6d, 0x5f, + 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x33, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, + 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, + 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x43, 0x6f, 0x6d, + 0x6d, 0x52, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x73, 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, 0x3a, 0x0a, 0x0a, 0x43, 0x6f, 0x6d, 0x6d, 0x53, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x12, 0x2c, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x12, + 0x0f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 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, 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -221,16 +224,18 @@ var file_storage_proto_goTypes = []interface{}{ (*Comm)(nil), // 0: Comm (*CommendRequest)(nil), // 1: CommendRequest (*CommendResponse)(nil), // 2: CommendResponse + (*StringxComm)(nil), // 3: StringxComm } var file_storage_proto_depIdxs = []int32{ - 0, // 0: CommendRequest.commends:type_name -> Comm - 1, // 1: CommServer.Commend:input_type -> CommendRequest - 2, // 2: CommServer.Commend:output_type -> CommendResponse - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 3, // 0: Comm.string_comm:type_name -> StringxComm + 0, // 1: CommendRequest.commends:type_name -> Comm + 1, // 2: CommServer.Commend:input_type -> CommendRequest + 2, // 3: CommServer.Commend:output_type -> CommendResponse + 3, // [3:4] is the sub-list for method output_type + 2, // [2:3] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_storage_proto_init() } @@ -238,6 +243,7 @@ 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.(*Comm); i { @@ -276,6 +282,9 @@ func file_storage_proto_init() { } } } + file_storage_proto_msgTypes[0].OneofWrappers = []interface{}{ + (*Comm_StringComm)(nil), + } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/structure/proto/stringx.pb.go b/pkg/proto/stringx.pb.go similarity index 97% rename from structure/proto/stringx.pb.go rename to pkg/proto/stringx.pb.go index 49b71ba..c963904 100644 --- a/structure/proto/stringx.pb.go +++ b/pkg/proto/stringx.pb.go @@ -219,9 +219,8 @@ var file_stringx_proto_rawDesc = []byte{ 0x52, 0x03, 0x67, 0x65, 0x74, 0x12, 0x1f, 0x0a, 0x03, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, 0x47, 0x65, 0x74, 0x48, 0x00, 0x52, 0x03, 0x73, 0x65, 0x74, 0x42, 0x0f, 0x0a, 0x0d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x5f, 0x78, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x42, 0x11, 0x5a, 0x0f, 0x73, 0x74, 0x72, 0x75, 0x63, - 0x74, 0x75, 0x72, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x5f, 0x78, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/structure/base.proto b/proto/structure/base.proto deleted file mode 100644 index 52a8293..0000000 --- a/proto/structure/base.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -option go_package = "structure/proto"; - -message BaseKey { - string key = 1; - int64 ttl = 2; -} \ No newline at end of file diff --git a/protobuf/base.proto b/protobuf/base.proto new file mode 100644 index 0000000..85ebaa6 --- /dev/null +++ b/protobuf/base.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +option go_package = "pkg/proto"; +import "google/protobuf/timestamp.proto"; + +message BaseKey { + string key = 1; + int64 ttl = 2; + google.protobuf.Timestamp expire = 3; +} \ No newline at end of file diff --git a/proto/storage/storage.proto b/protobuf/storage.proto similarity index 67% rename from proto/storage/storage.proto rename to protobuf/storage.proto index 34abd2a..c795937 100644 --- a/proto/storage/storage.proto +++ b/protobuf/storage.proto @@ -1,11 +1,12 @@ syntax = "proto3"; -option go_package = "storage/proto"; +option go_package = "pkg/proto"; +import "stringx.proto"; message Comm { - string key = 1; - string Operation = 2; - repeated string Option = 3; + oneof comm_option { + StringxComm string_comm = 1; + } } message CommendRequest { diff --git a/proto/structure/stringx.proto b/protobuf/stringx.proto similarity index 86% rename from proto/structure/stringx.proto rename to protobuf/stringx.proto index fbe46f5..edf4ebc 100644 --- a/proto/structure/stringx.proto +++ b/protobuf/stringx.proto @@ -2,7 +2,8 @@ syntax = "proto3"; import "base.proto"; -option go_package = "structure/proto"; +option go_package = "pkg/proto"; + message StringXSet { BaseKey key = 1; diff --git a/shell/proto.py b/shell/proto.py index 4927dec..9c2b57f 100644 --- a/shell/proto.py +++ b/shell/proto.py @@ -1,7 +1,7 @@ import os sysPath = os.getcwd() -protoPath = f"{sysPath}/proto" +protoPath = f"{sysPath}/protobuf" comm = """ protoc --proto_path={} --proto_path={} --go_out=plugins=grpc:{} {} diff --git a/storage/server/server.go b/storage/server/server.go index 41044c2..76de968 100644 --- a/storage/server/server.go +++ b/storage/server/server.go @@ -14,7 +14,7 @@ func NewServer() proto.CommServerServer { func (s *server) Commend( ctx context.Context, - request *proto.CommendRequest, + req *proto.CommendRequest, ) (*proto.CommendResponse, error) { return nil, nil }