refactor(structure, shell): update shell, structure
This commit is contained in:
parent
e3acfcd0fe
commit
ddd7a8a5ed
|
@ -7,6 +7,3 @@ STRING_X:
|
|||
- reduce
|
||||
- setbit
|
||||
- getbit
|
||||
|
||||
LIST_X:
|
||||
- set
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package stringx
|
||||
|
||||
import "gitee.com/timedb/wheatCache/pkg/structure"
|
||||
|
||||
type StringX struct {
|
||||
structure.KeyBase
|
||||
Value string
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ 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 = {}
|
||||
|
||||
|
|
|
@ -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()
|
|
@ -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"
|
||||
|
@ -29,15 +30,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,6 +59,7 @@ def set_structure_const_template(conf: dict):
|
|||
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
|
||||
|
||||
# 生成接口
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue