From 781fc4b6b7c3ae06c58cb5c7575aedafe84e298c Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sun, 29 Aug 2021 22:18:07 +0800 Subject: [PATCH 1/6] feat(struct): init struct interface --- pkg/structure/define/define.go | 1 + pkg/structure/define/interface.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 pkg/structure/define/define.go create mode 100644 pkg/structure/define/interface.go diff --git a/pkg/structure/define/define.go b/pkg/structure/define/define.go new file mode 100644 index 0000000..57c3969 --- /dev/null +++ b/pkg/structure/define/define.go @@ -0,0 +1 @@ +package define diff --git a/pkg/structure/define/interface.go b/pkg/structure/define/interface.go new file mode 100644 index 0000000..2d308cf --- /dev/null +++ b/pkg/structure/define/interface.go @@ -0,0 +1,22 @@ +package define + +type CacheValue interface { + LengthByte() int64 +} + +type ParseComm func(comm string) ([]string, error) + +type CacheStruct interface { + SizeByte() int64 + + // RollBack 事务相关 + RollBack() error + Begin() error + Comment() error + + ParseCommend(comm ParseComm) ([]string, error) + GetValue(opt ...string) CacheValue + SetValue(opt ...string) error + + Encode() ([]byte, error) +} From 13a3291e9e06f034d4252e99badf039cf360291a Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 31 Aug 2021 23:25:14 +0800 Subject: [PATCH 2/6] chore(project): rm .idea --- .idea/.gitignore | 8 -------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ .idea/wheat-cache.iml | 9 --------- 4 files changed, 31 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/wheat-cache.iml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index db83a83..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/wheat-cache.iml b/.idea/wheat-cache.iml deleted file mode 100644 index 5e764c4..0000000 --- a/.idea/wheat-cache.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file From a5a01b8e3346a559aa9513c72730ebbb852fa032 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 31 Aug 2021 23:30:14 +0800 Subject: [PATCH 3/6] chore(project): update project build file --- .gitignore | 7 +++++++ go.mod | 2 ++ go.sum | 7 +++++++ makefile | 10 ++++++++++ shell/proto.py | 25 +++++++++++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 shell/proto.py diff --git a/.gitignore b/.gitignore index f2dd955..826c304 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,15 @@ *.so *.dylib + # Test binary, built with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out + +.idea + + +# build file +/bin/storage \ No newline at end of file diff --git a/go.mod b/go.mod index 7d98767..d654f1b 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,6 @@ go 1.16 require ( github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 + google.golang.org/grpc v1.38.0 + google.golang.org/protobuf v1.26.0 ) diff --git a/go.sum b/go.sum index d6ff538..795c424 100644 --- a/go.sum +++ b/go.sum @@ -103,6 +103,7 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -116,6 +117,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -330,6 +332,7 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -462,6 +465,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -532,6 +536,7 @@ google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c h1:wtujag7C+4D6KMoulW9YauvK2lgdvCMS260jsqqBXr0= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= @@ -552,6 +557,7 @@ google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA5 google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -564,6 +570,7 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= diff --git a/makefile b/makefile index e69de29..93023d6 100644 --- a/makefile +++ b/makefile @@ -0,0 +1,10 @@ +BASE_PATH = $(shell pwd) +STORAGE_PATH = $(BASE_PATH)/storage +BASE_OUT = $(BASE_PATH)/bin + +dcgen: + python3 ./shell/proto.py + +.PHONY : build +build: + cd storage && go build -o $(BASE_OUT)/storage \ No newline at end of file diff --git a/shell/proto.py b/shell/proto.py new file mode 100644 index 0000000..b0195a7 --- /dev/null +++ b/shell/proto.py @@ -0,0 +1,25 @@ +import os + +sysPath = os.getcwd() +protoPath = f"{sysPath}/proto" + +comm = """ + protoc --proto_path={} --go_out=plugins=grpc:{} {} +""" + + +def out_proto(): + # 到达 storage + for root, dirs, files in os.walk(protoPath): + for f in files: + commend = comm.format(root, sysPath, f).strip() + err = os.system(commend) + + if err: + print(f, "-> out put err") + else: + print(f, "-> success") + + +if __name__ == '__main__': + out_proto() From 6453b2a0ce9e54a3b9d275cdfd6dc4f8335318db Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 31 Aug 2021 23:30:29 +0800 Subject: [PATCH 4/6] doc(project): update project build file doc --- doc/make/make.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 doc/make/make.md diff --git a/doc/make/make.md b/doc/make/make.md new file mode 100644 index 0000000..7b5e88c --- /dev/null +++ b/doc/make/make.md @@ -0,0 +1,11 @@ +## 构建工具文档 + +### 构建 proto (grpc-go) +```shell +make dcgen +``` + +### 编译全部的 go 项目 +```shell +make build +``` From 8c114bcb9a79e539eb9f5c308f636a87fae1125a Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 31 Aug 2021 23:30:55 +0800 Subject: [PATCH 5/6] chore(project): add comm proto --- proto/storage/storage.proto | 23 +++ storage/proto/storage.pb.go | 377 ++++++++++++++++++++++++++++++++++++ 2 files changed, 400 insertions(+) create mode 100644 proto/storage/storage.proto create mode 100644 storage/proto/storage.pb.go diff --git a/proto/storage/storage.proto b/proto/storage/storage.proto new file mode 100644 index 0000000..34abd2a --- /dev/null +++ b/proto/storage/storage.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +option go_package = "storage/proto"; + +message Comm { + string key = 1; + string Operation = 2; + repeated string Option = 3; +} + +message CommendRequest { + repeated Comm commends = 1; +} + +message CommendResponse { + repeated string result = 1; +} + +service CommServer { + rpc Commend (CommendRequest) returns (CommendResponse); +} + + diff --git a/storage/proto/storage.pb.go b/storage/proto/storage.pb.go new file mode 100644 index 0000000..2440907 --- /dev/null +++ b/storage/proto/storage.pb.go @@ -0,0 +1,377 @@ +// 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 Comm struct { + state protoimpl.MessageState + 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"` +} + +func (x *Comm) Reset() { + *x = Comm{} + if protoimpl.UnsafeEnabled { + mi := &file_storage_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Comm) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Comm) ProtoMessage() {} + +func (x *Comm) 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 Comm.ProtoReflect.Descriptor instead. +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 + } + return nil +} + +type CommendRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Commends []*Comm `protobuf:"bytes,1,rep,name=commends,proto3" json:"commends,omitempty"` +} + +func (x *CommendRequest) Reset() { + *x = CommendRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_storage_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CommendRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CommendRequest) ProtoMessage() {} + +func (x *CommendRequest) ProtoReflect() protoreflect.Message { + mi := &file_storage_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 CommendRequest.ProtoReflect.Descriptor instead. +func (*CommendRequest) Descriptor() ([]byte, []int) { + return file_storage_proto_rawDescGZIP(), []int{1} +} + +func (x *CommendRequest) GetCommends() []*Comm { + if x != nil { + return x.Commends + } + return nil +} + +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[2] + 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[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 CommendResponse.ProtoReflect.Descriptor instead. +func (*CommendResponse) Descriptor() ([]byte, []int) { + return file_storage_proto_rawDescGZIP(), []int{2} +} + +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, 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, +} + +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, 3) +var file_storage_proto_goTypes = []interface{}{ + (*Comm)(nil), // 0: Comm + (*CommendRequest)(nil), // 1: CommendRequest + (*CommendResponse)(nil), // 2: CommendResponse +} +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 +} + +func init() { file_storage_proto_init() } +func file_storage_proto_init() { + if File_storage_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_storage_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Comm); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_storage_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CommendRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_storage_proto_msgTypes[2].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: 3, + 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 { + Commend(ctx context.Context, in *CommendRequest, opts ...grpc.CallOption) (*CommendResponse, error) +} + +type commServerClient struct { + cc grpc.ClientConnInterface +} + +func NewCommServerClient(cc grpc.ClientConnInterface) CommServerClient { + return &commServerClient{cc} +} + +func (c *commServerClient) Commend(ctx context.Context, in *CommendRequest, opts ...grpc.CallOption) (*CommendResponse, error) { + out := new(CommendResponse) + err := c.cc.Invoke(ctx, "/CommServer/Commend", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// CommServerServer is the server API for CommServer service. +type CommServerServer interface { + Commend(context.Context, *CommendRequest) (*CommendResponse, error) +} + +// UnimplementedCommServerServer can be embedded to have forward compatible implementations. +type UnimplementedCommServerServer struct { +} + +func (*UnimplementedCommServerServer) Commend(context.Context, *CommendRequest) (*CommendResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Commend not implemented") +} + +func RegisterCommServerServer(s *grpc.Server, srv CommServerServer) { + s.RegisterService(&_CommServer_serviceDesc, srv) +} + +func _CommServer_Commend_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CommendRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommServerServer).Commend(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/CommServer/Commend", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommServerServer).Commend(ctx, req.(*CommendRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _CommServer_serviceDesc = grpc.ServiceDesc{ + ServiceName: "CommServer", + HandlerType: (*CommServerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Commend", + Handler: _CommServer_Commend_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "storage.proto", +} From 30e182d018e90a6903026fef61f9d93411e52ac7 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 31 Aug 2021 23:31:31 +0800 Subject: [PATCH 6/6] feat(storage): add storage server --- storage/cmd/root.go | 50 ++++++++++++++++++++++++++++++++-------- storage/server/server.go | 20 ++++++++++++++++ 2 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 storage/server/server.go diff --git a/storage/cmd/root.go b/storage/cmd/root.go index e1bac4e..d26625a 100644 --- a/storage/cmd/root.go +++ b/storage/cmd/root.go @@ -3,8 +3,16 @@ package cmd import ( "fmt" + "gitee.com/timedb/wheatCache/storage/proto" + "gitee.com/timedb/wheatCache/storage/server" "github.com/spf13/cobra" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" + "log" + "net" "os" + "os/signal" + "syscall" "github.com/spf13/viper" ) @@ -14,16 +22,40 @@ var cfgFile string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "storage", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: + Short: "storage", + Long: `start storage server`, + Run: func(cmd *cobra.Command, args []string) { + storageServer := server.NewServer() + // 先写死, 等配置文件 + listen, err := net.Listen("tcp", ":5201") + if err != nil { + log.Panicln(err) + } + s := grpc.NewServer() + proto.RegisterCommServerServer(s, storageServer) + reflection.Register(s) -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + c := make(chan os.Signal) + signal.Notify(c, syscall.SIGHUP, syscall.SIGINT) + go func() { + select { + case <-c: + s.Stop() + + msg := ` + |-------Wheat tools---------| + | see you next time | + |thank you for your efforts | + |---------------------------| + ` + fmt.Println(msg) + } + }() + + if err := s.Serve(listen); err != nil { + log.Panicln(err) + } + }, } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/storage/server/server.go b/storage/server/server.go new file mode 100644 index 0000000..41044c2 --- /dev/null +++ b/storage/server/server.go @@ -0,0 +1,20 @@ +package server + +import ( + context "context" + "gitee.com/timedb/wheatCache/storage/proto" +) + +type server struct{} + +func NewServer() proto.CommServerServer { + ser := &server{} + return ser +} + +func (s *server) Commend( + ctx context.Context, + request *proto.CommendRequest, +) (*proto.CommendResponse, error) { + return nil, nil +}