forked from p53841790/wheat-cache
!25 update proto auto tool
Merge pull request !25 from 百里酚蓝/feat-stringx
This commit is contained in:
commit
76c203c37a
|
@ -6,4 +6,7 @@ STRING_X:
|
|||
- add
|
||||
- reduce
|
||||
- setbit
|
||||
- getbit
|
||||
- getbit
|
||||
|
||||
LIST_X:
|
||||
- set
|
|
@ -0,0 +1,7 @@
|
|||
syntax = "proto3";
|
||||
import "base.proto";
|
||||
option go_package = "pkg/proto";
|
||||
|
||||
message SetRequest {
|
||||
BaseKey key = 1;
|
||||
}
|
|
@ -1,13 +1,23 @@
|
|||
// Code generated by gen-struct. DO NOT EDIT.
|
||||
// make gen-protobuf generated
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
option go_package = "pkg/proto";
|
||||
|
||||
import "stringx.proto";
|
||||
import "listx.proto";
|
||||
|
||||
message CommendResponse {
|
||||
repeated string result = 1;
|
||||
}
|
||||
|
||||
service CommServer {
|
||||
rpc Set (SetRequest) returns (CommendResponse);
|
||||
rpc Get (GetRequest) returns (CommendResponse);
|
||||
rpc Add (AddRequest) returns (CommendResponse);
|
||||
rpc Reduce (ReduceRequest) returns (CommendResponse);
|
||||
rpc Setbit (SetbitRequest) returns (CommendResponse);
|
||||
rpc Getbit (GetbitRequest) returns (CommendResponse);
|
||||
rpc Set (SetRequest) returns (CommendResponse);
|
||||
}
|
|
@ -24,53 +24,64 @@ def load_conf():
|
|||
key = to_camel(key).lower()
|
||||
cfg_camel[key] = [to_camel(v) for v in val]
|
||||
|
||||
# print(cfg_camel)
|
||||
|
||||
return cfg, cfg_camel
|
||||
|
||||
|
||||
# 生成文件,并写入
|
||||
def mkdir(cfg_camel):
|
||||
'''生成对应的数据结构proto文件'''
|
||||
def mk_structure(cfg_camel):
|
||||
path = "protobuf"
|
||||
path = path.strip()
|
||||
# 判断路径是否存在
|
||||
isExists = os.path.exists(path)
|
||||
# 判断结果
|
||||
if not isExists:
|
||||
os.makedirs(path)
|
||||
print(path + ' 创建成功')
|
||||
else: # 如果目录存在则不创建,并提示目录已存在
|
||||
# print(path + ' 目录已存在')
|
||||
for key,value in cfg_camel.items():
|
||||
# print(key)
|
||||
proto_path = path + '/' + key + '.proto'
|
||||
if not os.path.exists(proto_path): # 如果这个文件不存在
|
||||
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}\n')
|
||||
file.close()
|
||||
else: # 如果这个文件存在
|
||||
with open(proto_path) as f:
|
||||
line = f.readlines()
|
||||
# print(line)
|
||||
f.close()
|
||||
for v in value:
|
||||
function = v + 'Request'
|
||||
flag = 0
|
||||
for l in line:
|
||||
if function in l:
|
||||
flag=1
|
||||
break
|
||||
if flag == 0:
|
||||
file = open(proto_path,'a')
|
||||
file.write('\nmessage ' + v +'Request '+'{\n BaseKey key = 1;\n}\n')
|
||||
file.close()
|
||||
flag = 0
|
||||
storagePath = f"{protobufPath}/storage.proto"
|
||||
for key, value in cfg_camel.items():
|
||||
proto_path = path + '/' + key + '.proto'
|
||||
if not os.path.exists(proto_path): # 如果这个文件不存在
|
||||
'''生成对应的数据结构proto文件'''
|
||||
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.close()
|
||||
|
||||
else: # 如果这个文件存在
|
||||
'''更新数据结构proto文件'''
|
||||
with open(proto_path) as f:
|
||||
line = f.readlines()
|
||||
f.close()
|
||||
for v in value:
|
||||
function = v + 'Request'
|
||||
flag = 0
|
||||
for l in line:
|
||||
if function in l:
|
||||
flag=1
|
||||
break
|
||||
if flag == 0:
|
||||
file = open(proto_path,'a')
|
||||
file.write('\nmessage ' + v +'Request '+'{\n BaseKey key = 1;\n}')
|
||||
file.close()
|
||||
flag = 0
|
||||
|
||||
print(f"{key}.proto", "-> success")
|
||||
|
||||
|
||||
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.write('\nmessage CommendResponse {\n repeated string result = 1;\n}\n\nservice CommServer {\n')
|
||||
for key,value in cfg_camel.items():
|
||||
for v in value:
|
||||
file.write(' rpc '+ v +' ('+ v +'Request) returns (CommendResponse);\n')
|
||||
file.write('}')
|
||||
file.close()
|
||||
print("storage.proto", "-> success")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf, cfg_camel = load_conf()
|
||||
#
|
||||
mkdir(cfg_camel)
|
||||
mk_structure(cfg_camel) # 生成对应的数据结构proto文件
|
||||
mk_storage(cfg_camel)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue