From 8cfed8b325c42644f4da0f7e4bf2348c5f77bc59 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sun, 5 Sep 2021 17:50:38 +0800 Subject: [PATCH 1/6] doc(struct): add doc --- ...2\241\350\247\243\345\206\263\346\226\271\346\241\210.md" | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 "doc/RDB + AOF \347\232\204\344\272\213\345\212\241\350\247\243\345\206\263\346\226\271\346\241\210.md" diff --git "a/doc/RDB + AOF \347\232\204\344\272\213\345\212\241\350\247\243\345\206\263\346\226\271\346\241\210.md" "b/doc/RDB + AOF \347\232\204\344\272\213\345\212\241\350\247\243\345\206\263\346\226\271\346\241\210.md" new file mode 100644 index 0000000..e547dfa --- /dev/null +++ "b/doc/RDB + AOF \347\232\204\344\272\213\345\212\241\350\247\243\345\206\263\346\226\271\346\241\210.md" @@ -0,0 +1,5 @@ +### RDB + AOF 的事务解决方案 + + + +![事务RDB方案](https://gitee.com/timedb/img/raw/master/images/事务RDB方案.svg) \ No newline at end of file -- Gitee From c84873208b468a2b4bb1cc0b7afecc3912a7d470 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sun, 5 Sep 2021 21:27:08 +0800 Subject: [PATCH 2/6] chore(project): add conf --- .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 2 +- conf/public_conf.go | 4 ++-- makefile | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md index 66d4332..a7104da 100644 --- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -7,7 +7,7 @@ ### 描述(做了什么,变更了什么) -### 测试用例(新增、改动、可能影响的功能) +### 影响到的模块 diff --git a/conf/public_conf.go b/conf/public_conf.go index 56153da..ff0aadd 100644 --- a/conf/public_conf.go +++ b/conf/public_conf.go @@ -20,9 +20,9 @@ func init() { case nil: case viper.ConfigFileNotFoundError: formatPath := []string{linuxPath, devPath, devPath} - log.Fatalf("The profile could not be read, read path:%v", formatPath) + log.Fatalf("the profile could not be read, read path:%v", formatPath) default: - log.Fatalf("The resolution of the profile failed, err: %v", err) + log.Fatalf("the resolution of the profile failed, err: %v", err) } } diff --git a/makefile b/makefile index b4525c1..add950c 100644 --- a/makefile +++ b/makefile @@ -11,4 +11,8 @@ build: .PHONY: install install: - @make build \ No newline at end of file + @make build + +.PHONY: dev +dev: + @./bin/storage storage \ No newline at end of file -- Gitee From 40dd0dd91afe608808a85b7122ddb0e751aaea7f Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Thu, 16 Sep 2021 13:53:52 +0800 Subject: [PATCH 3/6] feat(stringx): add stringx init interface --- pkg/structure/define.go | 1 + pkg/structure/define/define.go | 1 - pkg/structure/{define => }/interface.go | 6 ++- pkg/structure/stringx/option.go | 1 + pkg/structure/stringx/string.go | 57 +++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 pkg/structure/define.go delete mode 100644 pkg/structure/define/define.go rename pkg/structure/{define => }/interface.go (72%) create mode 100644 pkg/structure/stringx/option.go create mode 100644 pkg/structure/stringx/string.go diff --git a/pkg/structure/define.go b/pkg/structure/define.go new file mode 100644 index 0000000..6fe4564 --- /dev/null +++ b/pkg/structure/define.go @@ -0,0 +1 @@ +package structure diff --git a/pkg/structure/define/define.go b/pkg/structure/define/define.go deleted file mode 100644 index 57c3969..0000000 --- a/pkg/structure/define/define.go +++ /dev/null @@ -1 +0,0 @@ -package define diff --git a/pkg/structure/define/interface.go b/pkg/structure/interface.go similarity index 72% rename from pkg/structure/define/interface.go rename to pkg/structure/interface.go index 2d308cf..78fdfcb 100644 --- a/pkg/structure/define/interface.go +++ b/pkg/structure/interface.go @@ -1,4 +1,4 @@ -package define +package structure type CacheValue interface { LengthByte() int64 @@ -9,9 +9,11 @@ type ParseComm func(comm string) ([]string, error) type CacheStruct interface { SizeByte() int64 - // RollBack 事务相关 + // TODO RollBack 事务相关, V2 实现 RollBack() error + // Begin 事务相关, V2 实现 Begin() error + // Comment 事务相关, V2 实现 Comment() error ParseCommend(comm ParseComm) ([]string, error) diff --git a/pkg/structure/stringx/option.go b/pkg/structure/stringx/option.go new file mode 100644 index 0000000..653ddc2 --- /dev/null +++ b/pkg/structure/stringx/option.go @@ -0,0 +1 @@ +package stringx diff --git a/pkg/structure/stringx/string.go b/pkg/structure/stringx/string.go new file mode 100644 index 0000000..6b5b3a4 --- /dev/null +++ b/pkg/structure/stringx/string.go @@ -0,0 +1,57 @@ +package stringx + +import ( + "unsafe" + + structure "gitee.com/timedb/wheatCache/pkg/structure/define" +) + +type StringxInt struct { + val int +} + +type StringxFloat struct { + val float64 +} + +type Stringx struct { + ValFloat StringxFloat + ValInt StringxInt + ValString string +} + +func (s *Stringx) SizeByte() int64 { + size := unsafe.Sizeof(s) + return int64(size) +} + +// RollBack 事务相关, V2 实现 +func (s *Stringx) RollBack() error { + panic("not implemented") // TODO: Implement +} + +// Begin 事务相关, V2 实现 +func (s *Stringx) Begin() error { + panic("not implemented") // TODO: Implement +} + +// RollBack 事务相关, V2 实现 +func (s *Stringx) Comment() error { + panic("not implemented") // TODO: Implement +} + +func (s *Stringx) ParseCommend(comm structure.ParseComm) ([]string, error) { + panic("not implemented") // TODO: Implement +} + +func (s *Stringx) GetValue(opt ...string) structure.CacheValue { + panic("not implemented") // TODO: Implement +} + +func (s *Stringx) SetValue(opt ...string) error { + panic("not implemented") // TODO: Implement +} + +func (s *Stringx) Encode() ([]byte, error) { + panic("not implemented") // TODO: Implement +} -- Gitee From b902c8cc1f8df21124f2a0c5c9b40839247eb237 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Thu, 16 Sep 2021 20:43:03 +0800 Subject: [PATCH 4/6] feat(structure-tools): add structure tools --- makefile | 7 +- pkg/structure/define.go | 1 - proto/structure/base.proto | 8 + proto/structure/stringx.proto | 21 ++ shell/make-struct.py | 72 ++++ shell/proto.py | 4 +- structure/define.go | 15 + structure/generate/structure.gen.go | 41 +++ structure/generate/tem.yaml | 10 + {pkg/structure => structure}/interface.go | 2 - structure/proto/base.pb.go | 150 ++++++++ structure/proto/stringx.pb.go | 324 ++++++++++++++++++ .../structure => structure}/stringx/option.go | 0 .../structure => structure}/stringx/string.go | 10 +- 14 files changed, 650 insertions(+), 15 deletions(-) delete mode 100644 pkg/structure/define.go create mode 100644 proto/structure/base.proto create mode 100644 proto/structure/stringx.proto create mode 100644 shell/make-struct.py create mode 100644 structure/define.go create mode 100644 structure/generate/structure.gen.go create mode 100644 structure/generate/tem.yaml rename {pkg/structure => structure}/interface.go (85%) create mode 100644 structure/proto/base.pb.go create mode 100644 structure/proto/stringx.pb.go rename {pkg/structure => structure}/stringx/option.go (100%) rename {pkg/structure => structure}/stringx/string.go (76%) diff --git a/makefile b/makefile index add950c..c98cc26 100644 --- a/makefile +++ b/makefile @@ -15,4 +15,9 @@ install: .PHONY: dev dev: - @./bin/storage storage \ No newline at end of file + @./bin/storage storage + +.PHONY: gen-struct +gen-struct: + @python3 ./shell/make-struct.py + @gofmt -w $(BASE_PATH)/structure/generate/structure.gen.go \ No newline at end of file diff --git a/pkg/structure/define.go b/pkg/structure/define.go deleted file mode 100644 index 6fe4564..0000000 --- a/pkg/structure/define.go +++ /dev/null @@ -1 +0,0 @@ -package structure diff --git a/proto/structure/base.proto b/proto/structure/base.proto new file mode 100644 index 0000000..52a8293 --- /dev/null +++ b/proto/structure/base.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +option go_package = "structure/proto"; + +message BaseKey { + string key = 1; + int64 ttl = 2; +} \ No newline at end of file diff --git a/proto/structure/stringx.proto b/proto/structure/stringx.proto new file mode 100644 index 0000000..fbe46f5 --- /dev/null +++ b/proto/structure/stringx.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +import "base.proto"; + +option go_package = "structure/proto"; + +message StringXSet { + BaseKey key = 1; + string value = 2; +} + +message StringxGet { + BaseKey key = 1; +} + +message StringxComm { + oneof string_x_comm { + StringXSet get = 1; + StringxGet set = 2; + } +} \ No newline at end of file diff --git a/shell/make-struct.py b/shell/make-struct.py new file mode 100644 index 0000000..3a9f981 --- /dev/null +++ b/shell/make-struct.py @@ -0,0 +1,72 @@ +import os +from jinja2 import Template +import yaml + +sysPath = os.getcwd() + +tem_text = '''// Code generated by gen-struct. DO NOT EDIT. +// make gen-struct generated + +package generate + +const ( + DEFAULT_KEY = iota + {% for key in keys %} + {{key}} + {% endfor %} +) + +const ( + DEFAULT_COMM = iota + {% for key in sets %} + {{key}} + {% endfor %} +) + +var CommKey = map[string]int { +{% for kmp in key_maps %} + {% for comm in kmp.val %} + "{{comm}}": {{kmp.key}}, + {% endfor %} +{% endfor %} +} +''' + + +class KeyMap(object): + def __init__(self, key, val) -> None: + self.key = key + self.val = val + + +def load_conf(): + conf_path = f"{sysPath}/structure/generate/tem.yaml" + with open(conf_path, 'r', encoding='utf-8') as f: + cfg = f.read() + + cfg = yaml.load(cfg) + + return cfg + + +def set_structure_template(conf: dict): + keys = conf.keys() + key_map = [] + val_set = [] + for k, v in conf.items(): + key_map.append(KeyMap(key=k, val=v)) + + for val in v: + val_set.append(val.upper() + "_COMM") + + template = Template(tem_text) + text = template.render(keys=keys, key_maps=key_map, sets=val_set) + + temp_path = f"{sysPath}/structure/generate/structure.gen.go" + with open(temp_path, 'w', encoding='utf-8') as f: + f.write(text) + + +if __name__ == "__main__": + conf = load_conf() + set_structure_template(conf) diff --git a/shell/proto.py b/shell/proto.py index b0195a7..4927dec 100644 --- a/shell/proto.py +++ b/shell/proto.py @@ -4,7 +4,7 @@ sysPath = os.getcwd() protoPath = f"{sysPath}/proto" comm = """ - protoc --proto_path={} --go_out=plugins=grpc:{} {} + protoc --proto_path={} --proto_path={} --go_out=plugins=grpc:{} {} """ @@ -12,7 +12,7 @@ def out_proto(): # 到达 storage for root, dirs, files in os.walk(protoPath): for f in files: - commend = comm.format(root, sysPath, f).strip() + commend = comm.format(protoPath, root, sysPath, f).strip() err = os.system(commend) if err: diff --git a/structure/define.go b/structure/define.go new file mode 100644 index 0000000..53b61f7 --- /dev/null +++ b/structure/define.go @@ -0,0 +1,15 @@ +package structure + +const ( + STRING_X = iota + LIST_X + SET_X + Z_SET_X +) + +// SetComm 操作描述 +type SetComm struct { + Typ int + Opt string + Params []string +} diff --git a/structure/generate/structure.gen.go b/structure/generate/structure.gen.go new file mode 100644 index 0000000..214098f --- /dev/null +++ b/structure/generate/structure.gen.go @@ -0,0 +1,41 @@ +// Code generated by gen-struct. DO NOT EDIT. +// make gen-struct generated + +package generate + +const ( + DEFAULT_KEY = iota + + STRING_X +) + +const ( + DEFAULT_COMM = iota + + SET_COMM + + GET_COMM + + ADD_COMM + + REDUCE_COMM + + SETBIT_COMM + + GETBIT_COMM +) + +var CommKey = map[string]int{ + + "set": STRING_X, + + "get": STRING_X, + + "add": STRING_X, + + "reduce": STRING_X, + + "setbit": STRING_X, + + "getbit": STRING_X, +} diff --git a/structure/generate/tem.yaml b/structure/generate/tem.yaml new file mode 100644 index 0000000..945712e --- /dev/null +++ b/structure/generate/tem.yaml @@ -0,0 +1,10 @@ +# 这里定义结构体的支持的命令, 以后也许会添加结构体的命令验证 + +STRING_X: + - set + - get + - add + - reduce + - setbit + - getbit + diff --git a/pkg/structure/interface.go b/structure/interface.go similarity index 85% rename from pkg/structure/interface.go rename to structure/interface.go index 78fdfcb..f0935e1 100644 --- a/pkg/structure/interface.go +++ b/structure/interface.go @@ -17,8 +17,6 @@ type CacheStruct interface { Comment() error ParseCommend(comm ParseComm) ([]string, error) - GetValue(opt ...string) CacheValue - SetValue(opt ...string) error Encode() ([]byte, error) } diff --git a/structure/proto/base.pb.go b/structure/proto/base.pb.go new file mode 100644 index 0000000..0553add --- /dev/null +++ b/structure/proto/base.pb.go @@ -0,0 +1,150 @@ +// 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" + 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"` +} + +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 +} + +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, +} + +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 +} +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 +} + +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/structure/proto/stringx.pb.go b/structure/proto/stringx.pb.go new file mode 100644 index 0000000..49b71ba --- /dev/null +++ b/structure/proto/stringx.pb.go @@ -0,0 +1,324 @@ +// 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 StringXSet 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 *StringXSet) Reset() { + *x = StringXSet{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StringXSet) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StringXSet) ProtoMessage() {} + +func (x *StringXSet) 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 StringXSet.ProtoReflect.Descriptor instead. +func (*StringXSet) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{0} +} + +func (x *StringXSet) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +func (x *StringXSet) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +type StringxGet struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *StringxGet) Reset() { + *x = StringxGet{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StringxGet) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StringxGet) ProtoMessage() {} + +func (x *StringxGet) 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 StringxGet.ProtoReflect.Descriptor instead. +func (*StringxGet) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{1} +} + +func (x *StringxGet) GetKey() *BaseKey { + if x != nil { + return x.Key + } + return nil +} + +type StringxComm struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Types that are assignable to StringXComm: + // *StringxComm_Get + // *StringxComm_Set + StringXComm isStringxComm_StringXComm `protobuf_oneof:"string_x_comm"` +} + +func (x *StringxComm) Reset() { + *x = StringxComm{} + if protoimpl.UnsafeEnabled { + mi := &file_stringx_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StringxComm) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StringxComm) ProtoMessage() {} + +func (x *StringxComm) 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 StringxComm.ProtoReflect.Descriptor instead. +func (*StringxComm) Descriptor() ([]byte, []int) { + return file_stringx_proto_rawDescGZIP(), []int{2} +} + +func (m *StringxComm) GetStringXComm() isStringxComm_StringXComm { + if m != nil { + return m.StringXComm + } + return nil +} + +func (x *StringxComm) GetGet() *StringXSet { + if x, ok := x.GetStringXComm().(*StringxComm_Get); ok { + return x.Get + } + return nil +} + +func (x *StringxComm) GetSet() *StringxGet { + if x, ok := x.GetStringXComm().(*StringxComm_Set); ok { + return x.Set + } + return nil +} + +type isStringxComm_StringXComm interface { + isStringxComm_StringXComm() +} + +type StringxComm_Get struct { + Get *StringXSet `protobuf:"bytes,1,opt,name=get,proto3,oneof"` +} + +type StringxComm_Set struct { + Set *StringxGet `protobuf:"bytes,2,opt,name=set,proto3,oneof"` +} + +func (*StringxComm_Get) isStringxComm_StringXComm() {} + +func (*StringxComm_Set) isStringxComm_StringXComm() {} + +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, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x58, 0x53, 0x65, 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, 0x53, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, 0x47, 0x65, 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, 0x60, 0x0a, 0x0b, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, + 0x43, 0x6f, 0x6d, 0x6d, 0x12, 0x1f, 0x0a, 0x03, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0b, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x58, 0x53, 0x65, 0x74, 0x48, 0x00, + 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, +} + +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, 3) +var file_stringx_proto_goTypes = []interface{}{ + (*StringXSet)(nil), // 0: StringXSet + (*StringxGet)(nil), // 1: StringxGet + (*StringxComm)(nil), // 2: StringxComm + (*BaseKey)(nil), // 3: BaseKey +} +var file_stringx_proto_depIdxs = []int32{ + 3, // 0: StringXSet.key:type_name -> BaseKey + 3, // 1: StringxGet.key:type_name -> BaseKey + 0, // 2: StringxComm.get:type_name -> StringXSet + 1, // 3: StringxComm.set:type_name -> StringxGet + 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.(*StringXSet); 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.(*StringxGet); 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.(*StringxComm); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_stringx_proto_msgTypes[2].OneofWrappers = []interface{}{ + (*StringxComm_Get)(nil), + (*StringxComm_Set)(nil), + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stringx_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + 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/stringx/option.go b/structure/stringx/option.go similarity index 100% rename from pkg/structure/stringx/option.go rename to structure/stringx/option.go diff --git a/pkg/structure/stringx/string.go b/structure/stringx/string.go similarity index 76% rename from pkg/structure/stringx/string.go rename to structure/stringx/string.go index 6b5b3a4..6a7522c 100644 --- a/pkg/structure/stringx/string.go +++ b/structure/stringx/string.go @@ -3,7 +3,7 @@ package stringx import ( "unsafe" - structure "gitee.com/timedb/wheatCache/pkg/structure/define" + "gitee.com/timedb/wheatCache/pkg/structure" ) type StringxInt struct { @@ -44,14 +44,6 @@ func (s *Stringx) ParseCommend(comm structure.ParseComm) ([]string, error) { panic("not implemented") // TODO: Implement } -func (s *Stringx) GetValue(opt ...string) structure.CacheValue { - panic("not implemented") // TODO: Implement -} - -func (s *Stringx) SetValue(opt ...string) error { - panic("not implemented") // TODO: Implement -} - func (s *Stringx) Encode() ([]byte, error) { panic("not implemented") // TODO: Implement } -- Gitee From 221dbdd6d4a9d30badc38b4330140be6e69578ec Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Thu, 16 Sep 2021 21:45:51 +0800 Subject: [PATCH 5/6] doc(make): update makefile doc --- doc/make/make.md | 6 ++++++ structure/stringx/string.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/make/make.md b/doc/make/make.md index 7b5e88c..b0afd4e 100644 --- a/doc/make/make.md +++ b/doc/make/make.md @@ -9,3 +9,9 @@ make dcgen ```shell make build ``` + +### 启动 storage 服务 +```shell +make dev +``` +### 根据配置生成 结构体命令 diff --git a/structure/stringx/string.go b/structure/stringx/string.go index 6a7522c..34ab783 100644 --- a/structure/stringx/string.go +++ b/structure/stringx/string.go @@ -3,7 +3,7 @@ package stringx import ( "unsafe" - "gitee.com/timedb/wheatCache/pkg/structure" + "gitee.com/timedb/wheatCache/structure" ) type StringxInt struct { -- Gitee 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 6/6] feat(structure-pkg): add storage pkg --- {structure => pkg}/proto/base.pb.go | 44 ++++++---- {storage => pkg}/proto/storage.pb.go | 93 +++++++++++---------- {structure => pkg}/proto/stringx.pb.go | 5 +- {proto/structure => protobuf}/base.proto | 4 +- {proto/storage => protobuf}/storage.proto | 9 +- {proto/structure => protobuf}/stringx.proto | 3 +- shell/proto.py | 2 +- storage/server/server.go | 2 +- 8 files changed, 95 insertions(+), 67 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%) rename {proto/structure => protobuf}/base.proto (40%) rename {proto/storage => protobuf}/storage.proto (67%) rename {proto/structure => protobuf}/stringx.proto (87%) 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 +func (m *Comm) GetCommOption() isComm_CommOption { + if m != nil { + return m.CommOption } - return "" + return nil } -func (x *Comm) GetOperation() string { - if x != nil { - return x.Operation +func (x *Comm) GetStringComm() *StringxComm { + if x, ok := x.GetCommOption().(*Comm_StringComm); ok { + return x.StringComm } - return "" + return nil } -func (x *Comm) GetOption() []string { - if x != nil { - return x.Option - } - 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/protobuf/base.proto similarity index 40% rename from proto/structure/base.proto rename to protobuf/base.proto index 52a8293..85ebaa6 100644 --- a/proto/structure/base.proto +++ b/protobuf/base.proto @@ -1,8 +1,10 @@ syntax = "proto3"; -option go_package = "structure/proto"; +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 87% 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 } -- Gitee