!28 创建 storage 模板

Merge pull request !28 from bandl/refactor-master
This commit is contained in:
bandl 2021-09-21 14:23:04 +00:00 committed by Gitee
commit 6637f4c77e
25 changed files with 532 additions and 350 deletions

1
go.mod
View File

@ -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
)

3
go.sum
View File

@ -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=

View File

@ -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:

1
pkg/log/define.go Normal file
View File

@ -0,0 +1 @@
package log

View File

@ -1 +0,0 @@
package define

3
pkg/lru/define.go Normal file
View File

@ -0,0 +1,3 @@
package lru
// define

View File

@ -1,3 +0,0 @@
package define
// define

1
pkg/middle/define.go Normal file
View File

@ -0,0 +1 @@
package middle

View File

@ -1 +0,0 @@
package define

View File

@ -1,3 +1,6 @@
// 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
@ -78,14 +81,25 @@ var file_storage_proto_rawDesc = []byte{
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,
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 (
@ -103,16 +117,28 @@ func file_storage_proto_rawDescGZIP() []byte {
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
(*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.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
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
@ -170,8 +196,12 @@ const _ = grpc.SupportPackageIsVersion6
//
// 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)
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 {
@ -182,15 +212,6 @@ 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...)
@ -200,45 +221,88 @@ func (c *commServerClient) Set(ctx context.Context, in *SetRequest, opts ...grpc
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 {
Get(context.Context, *GetRequest) (*CommendResponse, error)
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) Set(context.Context, *SetRequest) (*CommendResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Set 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_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 {
@ -257,17 +321,123 @@ func _CommServer_Set_Handler(srv interface{}, ctx context.Context, dec func(inte
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: "Set",
Handler: _CommServer_Set_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{},

View File

@ -25,8 +25,7 @@ type SetRequest struct {
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"`
Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
}
func (x *SetRequest) Reset() {
@ -68,13 +67,6 @@ func (x *SetRequest) GetKey() *BaseKey {
return nil
}
func (x *SetRequest) GetValue() string {
if x != nil {
return x.Value
}
return ""
}
type GetRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -127,8 +119,7 @@ type AddRequest struct {
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"`
Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
}
func (x *AddRequest) Reset() {
@ -170,14 +161,7 @@ func (x *AddRequest) GetKey() *BaseKey {
return nil
}
func (x *AddRequest) GetValue() int64 {
if x != nil {
return x.Value
}
return 0
}
type RedceRequest struct {
type ReduceRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -185,8 +169,8 @@ type RedceRequest struct {
Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
}
func (x *RedceRequest) Reset() {
*x = RedceRequest{}
func (x *ReduceRequest) Reset() {
*x = ReduceRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_stringx_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -194,13 +178,13 @@ func (x *RedceRequest) Reset() {
}
}
func (x *RedceRequest) String() string {
func (x *ReduceRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RedceRequest) ProtoMessage() {}
func (*ReduceRequest) ProtoMessage() {}
func (x *RedceRequest) ProtoReflect() protoreflect.Message {
func (x *ReduceRequest) ProtoReflect() protoreflect.Message {
mi := &file_stringx_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -212,12 +196,106 @@ func (x *RedceRequest) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use RedceRequest.ProtoReflect.Descriptor instead.
func (*RedceRequest) Descriptor() ([]byte, []int) {
// Deprecated: Use ReduceRequest.ProtoReflect.Descriptor instead.
func (*ReduceRequest) Descriptor() ([]byte, []int) {
return file_stringx_proto_rawDescGZIP(), []int{3}
}
func (x *RedceRequest) GetKey() *BaseKey {
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
}
@ -228,22 +306,25 @@ 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,
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, 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,
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, 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,
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 (
@ -258,24 +339,28 @@ func file_stringx_proto_rawDescGZIP() []byte {
return file_stringx_proto_rawDescData
}
var file_stringx_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
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
(*RedceRequest)(nil), // 3: RedceRequest
(*BaseKey)(nil), // 4: BaseKey
(*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{
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
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() }
@ -322,7 +407,31 @@ func file_stringx_proto_init() {
}
}
file_stringx_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*RedceRequest); i {
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:
@ -340,7 +449,7 @@ func file_stringx_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_stringx_proto_rawDesc,
NumEnums: 0,
NumMessages: 4,
NumMessages: 6,
NumExtensions: 0,
NumServices: 0,
},

View File

@ -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
}

View File

@ -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,
}
}

View File

@ -6,7 +6,4 @@ STRING_X:
- add
- reduce
- setbit
- getbit
LIST_X:
- set
- getbit

View File

@ -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)
}

View File

@ -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
}

View File

@ -1,8 +1,51 @@
package stringx
import "gitee.com/timedb/wheatCache/pkg/structure"
import "gitee.com/timedb/wheatCache/pkg/proto"
type StringX struct {
structure.KeyBase
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")
}

View File

@ -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;
}

View File

@ -1,7 +0,0 @@
syntax = "proto3";
import "base.proto";
option go_package = "pkg/proto";
message SetRequest {
BaseKey key = 1;
}

View File

@ -6,7 +6,6 @@ syntax = "proto3";
option go_package = "pkg/proto";
import "stringx.proto";
import "listx.proto";
message CommendResponse {
repeated string result = 1;
@ -19,5 +18,4 @@ service CommServer {
rpc Reduce (ReduceRequest) returns (CommendResponse);
rpc Setbit (SetbitRequest) returns (CommendResponse);
rpc Getbit (GetbitRequest) returns (CommendResponse);
rpc Set (SetRequest) returns (CommendResponse);
}

View File

@ -4,7 +4,6 @@ option go_package = "pkg/proto";
message SetRequest {
BaseKey key = 1;
string value = 2;
}
message GetRequest {

View File

@ -1,6 +1,5 @@
import os
from typing import Dict, List
from jinja2 import Template
import yaml
sysPath = os.getcwd()
@ -8,15 +7,17 @@ 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:
cfg = f.read()
cfg = yaml.load(cfg)
cfg = yaml.load(cfg, Loader=yaml.FullLoader)
cfg_camel = {}
@ -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)

View File

@ -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()

View File

@ -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"
@ -15,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('_')])
@ -29,15 +34,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,9 +63,8 @@ def set_structure_const_template(conf: dict):
with open(temp_path, 'w', encoding='utf-8') as f:
f.write(text)
# 生成接口
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()

View File

@ -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")
}