forked from p93542168/wheat-cache
feat(shell): update const gen
This commit is contained in:
parent
4459beba61
commit
e404f670a0
|
@ -4,8 +4,7 @@ import yaml
|
|||
from jinja2 import Template
|
||||
|
||||
sysPath = os.getcwd()
|
||||
tempPath = f"{sysPath}/pkg/structure/generate"
|
||||
structurePath = f"{sysPath}/pkg/structure"
|
||||
tempPath = f"{sysPath}/storage/temp"
|
||||
protobufPath = f"{sysPath}/protobuf"
|
||||
storagePath = f"{sysPath}/storage"
|
||||
|
||||
|
@ -14,7 +13,7 @@ class KeyMap(object):
|
|||
def __init__(self, key: str, val) -> None:
|
||||
self.key = key
|
||||
self.val = val
|
||||
self.upper = [v.upper() for v in val]
|
||||
self.upper = val
|
||||
|
||||
|
||||
def go_fmt(path: str):
|
||||
|
@ -27,7 +26,7 @@ def to_camel(val: str) -> str:
|
|||
|
||||
class KeyOption(object):
|
||||
def __init__(self, key, option):
|
||||
self.key = to_camel(key)
|
||||
self.key = key
|
||||
self.option = option
|
||||
|
||||
def __str__(self):
|
||||
|
@ -64,56 +63,23 @@ def set_structure_const_template(conf: dict):
|
|||
key_map.append(KeyMap(key=k, val=v))
|
||||
|
||||
for val in v:
|
||||
val_set.append(val.upper())
|
||||
val_set.append(val)
|
||||
|
||||
template = Template(tem_text)
|
||||
text = template.render(keys=keys, key_maps=key_map, sets=val_set)
|
||||
|
||||
temp_path = f"{structurePath}/const.gen.go"
|
||||
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
|
||||
|
||||
# 生成接口
|
||||
def set_structure_interface(conf):
|
||||
text = load_template("interface.template")
|
||||
Dic = {}
|
||||
template = Template(text)
|
||||
for i in conf.keys():
|
||||
x = i.lower().title()
|
||||
Dic["".join(x.split("_"))] = conf[i]
|
||||
yamlData = [Dic]
|
||||
text = template.render(Data=yamlData)
|
||||
temp_path = f"{structurePath}/interface.gen.go"
|
||||
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
|
||||
|
||||
def set_storage_server(server_conf):
|
||||
mod_name = [i.replace("_", "").lower() for i in server_conf.keys()]
|
||||
|
||||
option = []
|
||||
for key, item in server_conf.items():
|
||||
option.append(KeyOption(key, item))
|
||||
|
||||
text = load_template("storage.template")
|
||||
template = Template(text)
|
||||
text = template.render(option=option, mod_name=mod_name)
|
||||
temp_path = f"{storagePath}/server/single.gen.go"
|
||||
temp_path = f"{tempPath}/const.gen.go"
|
||||
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
|
||||
|
||||
def format_code_go():
|
||||
go_fmt(f"{structurePath}/interface.gen.go")
|
||||
go_fmt(f"{structurePath}/const.gen.go")
|
||||
go_fmt(f"{storagePath}/server/*.go")
|
||||
go_fmt(f"{tempPath}/const.gen.go")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf, cfg_camel = load_conf()
|
||||
set_structure_const_template(conf)
|
||||
# set_structure_interface(cfg_camel)
|
||||
# set_storage_server(cfg_camel)
|
||||
|
||||
set_structure_const_template(cfg_camel)
|
||||
# 格式化代码
|
||||
format_code_go()
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
// Code generated by gen-struct. DO NOT EDIT.
|
||||
// make gen-struct generated
|
||||
|
||||
package structure
|
||||
|
||||
const (
|
||||
DEFAULT_KEY = iota
|
||||
|
||||
STRING_X
|
||||
LIST_X
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_COMM = iota
|
||||
SET
|
||||
GET
|
||||
ADD
|
||||
REDUCE
|
||||
SETBIT
|
||||
GETBIT
|
||||
GETRANGE
|
||||
GETSET
|
||||
STRLEN
|
||||
SETNX
|
||||
LINDEX
|
||||
LLEN
|
||||
LPOP
|
||||
LPUSH
|
||||
LPUSHX
|
||||
LRANGE
|
||||
LREM
|
||||
LSET
|
||||
RPOP
|
||||
LTRIM
|
||||
RPUSH
|
||||
RPUSHX
|
||||
)
|
||||
|
||||
var CommKeyString = map[string]int{"set": STRING_X,
|
||||
"get": STRING_X,
|
||||
"add": STRING_X,
|
||||
"reduce": STRING_X,
|
||||
"setbit": STRING_X,
|
||||
"getbit": STRING_X,
|
||||
"getrange": STRING_X,
|
||||
"getset": STRING_X,
|
||||
"strlen": STRING_X,
|
||||
"setnx": STRING_X,
|
||||
"lindex": LIST_X,
|
||||
"llen": LIST_X,
|
||||
"lpop": LIST_X,
|
||||
"lpush": LIST_X,
|
||||
"lpushx": LIST_X,
|
||||
"lrange": LIST_X,
|
||||
"lrem": LIST_X,
|
||||
"lset": LIST_X,
|
||||
"rpop": LIST_X,
|
||||
"ltrim": LIST_X,
|
||||
"rpush": LIST_X,
|
||||
"rpushx": LIST_X,
|
||||
}
|
||||
|
||||
var CommKey = map[int]int{SET: STRING_X,
|
||||
GET: STRING_X,
|
||||
ADD: STRING_X,
|
||||
REDUCE: STRING_X,
|
||||
SETBIT: STRING_X,
|
||||
GETBIT: STRING_X,
|
||||
GETRANGE: STRING_X,
|
||||
GETSET: STRING_X,
|
||||
STRLEN: STRING_X,
|
||||
SETNX: STRING_X,
|
||||
LINDEX: LIST_X,
|
||||
LLEN: LIST_X,
|
||||
LPOP: LIST_X,
|
||||
LPUSH: LIST_X,
|
||||
LPUSHX: LIST_X,
|
||||
LRANGE: LIST_X,
|
||||
LREM: LIST_X,
|
||||
LSET: LIST_X,
|
||||
RPOP: LIST_X,
|
||||
LTRIM: LIST_X,
|
||||
RPUSH: LIST_X,
|
||||
RPUSHX: LIST_X,
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
// Code generated by gen-struct. DO NOT EDIT.
|
||||
// make gen-struct generated
|
||||
|
||||
package structure
|
||||
|
||||
const (
|
||||
DEFAULT_KEY = iota
|
||||
|
||||
STRING_X
|
||||
LIST_X
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_COMM = iota
|
||||
Set
|
||||
Get
|
||||
Add
|
||||
Reduce
|
||||
SetBit
|
||||
GetBit
|
||||
GetRange
|
||||
GetSet
|
||||
StrLen
|
||||
Setnx
|
||||
LIndex
|
||||
LLen
|
||||
LPop
|
||||
LPush
|
||||
LPushX
|
||||
LRange
|
||||
LRem
|
||||
LSet
|
||||
RPop
|
||||
LTrim
|
||||
RPush
|
||||
RPushX
|
||||
)
|
||||
|
||||
var CommKeyString = map[string]int{
|
||||
"Set": STRING_X,
|
||||
"Get": STRING_X,
|
||||
"Add": STRING_X,
|
||||
"Reduce": STRING_X,
|
||||
"SetBit": STRING_X,
|
||||
"GetBit": STRING_X,
|
||||
"GetRange": STRING_X,
|
||||
"GetSet": STRING_X,
|
||||
"StrLen": STRING_X,
|
||||
"Setnx": STRING_X,
|
||||
|
||||
"LIndex": LIST_X,
|
||||
"LLen": LIST_X,
|
||||
"LPop": LIST_X,
|
||||
"LPush": LIST_X,
|
||||
"LPushX": LIST_X,
|
||||
"LRange": LIST_X,
|
||||
"LRem": LIST_X,
|
||||
"LSet": LIST_X,
|
||||
"RPop": LIST_X,
|
||||
"LTrim": LIST_X,
|
||||
"RPush": LIST_X,
|
||||
"RPushX": LIST_X,
|
||||
}
|
||||
|
||||
var CommKey = map[int]int{
|
||||
Set: STRING_X,
|
||||
Get: STRING_X,
|
||||
Add: STRING_X,
|
||||
Reduce: STRING_X,
|
||||
SetBit: STRING_X,
|
||||
GetBit: STRING_X,
|
||||
GetRange: STRING_X,
|
||||
GetSet: STRING_X,
|
||||
StrLen: STRING_X,
|
||||
Setnx: STRING_X,
|
||||
|
||||
LIndex: LIST_X,
|
||||
LLen: LIST_X,
|
||||
LPop: LIST_X,
|
||||
LPush: LIST_X,
|
||||
LPushX: LIST_X,
|
||||
LRange: LIST_X,
|
||||
LRem: LIST_X,
|
||||
LSet: LIST_X,
|
||||
RPop: LIST_X,
|
||||
LTrim: LIST_X,
|
||||
RPush: LIST_X,
|
||||
RPushX: LIST_X,
|
||||
}
|
|
@ -18,7 +18,7 @@ const (
|
|||
)
|
||||
|
||||
var CommKeyString = map[string]int {
|
||||
{%- for kmp in key_maps -%}
|
||||
{%- for kmp in key_maps %}
|
||||
{% for comm in kmp.val -%}
|
||||
"{{comm}}": {{kmp.key}},
|
||||
{% endfor -%}
|
||||
|
@ -26,7 +26,7 @@ var CommKeyString = map[string]int {
|
|||
}
|
||||
|
||||
var CommKey = map[int]int {
|
||||
{%- for kmp in key_maps -%}
|
||||
{%- for kmp in key_maps %}
|
||||
{% for comm in kmp.upper -%}
|
||||
{{comm}}: {{kmp.key}},
|
||||
{% endfor -%}
|
Loading…
Reference in New Issue