!23 自动生成interface脚本
Merge pull request !23 from K-on/feat-update-tamplate
This commit is contained in:
commit
23baebe2d7
4
makefile
4
makefile
|
@ -17,8 +17,8 @@ install:
|
|||
dev:
|
||||
@./bin/storage storage
|
||||
|
||||
.PHONY: gen-struct
|
||||
gen-struct:
|
||||
.PHONY: gen-struct-const
|
||||
gen-struct-const:
|
||||
@python3 ./shell/make-struct.py
|
||||
|
||||
.PHONY: gen-protobuf
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
// Code generated by gen-struct. DO NOT EDIT.
|
||||
// Code generated by gen-struct-const. DO NOT EDIT.
|
||||
// make gen-struct generated
|
||||
|
||||
package generate
|
||||
|
||||
const (
|
||||
DEFAULT_KEY = iota
|
||||
{% for key in keys %}
|
||||
{% for key in keys -%}
|
||||
{{key}}
|
||||
{% endfor %}
|
||||
{%- endfor %}
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_COMM = iota
|
||||
{% for key in sets %}
|
||||
{% for key in sets -%}
|
||||
{{key}}
|
||||
{% endfor %}
|
||||
)
|
||||
|
||||
var CommKeyString = map[string]int {
|
||||
{% for kmp in key_maps %}
|
||||
{% for comm in kmp.val %}
|
||||
{%- for kmp in key_maps -%}
|
||||
{% for comm in kmp.val -%}
|
||||
"{{comm}}": {{kmp.key}},
|
||||
{% endfor %}
|
||||
{% endfor -%}
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
var CommKey = map[int]int {
|
||||
{% for kmp in key_maps %}
|
||||
{% for comm in kmp.upper %}
|
||||
{%- for kmp in key_maps -%}
|
||||
{% for comm in kmp.upper -%}
|
||||
{{comm}}: {{kmp.key}},
|
||||
{% endfor %}
|
||||
{% endfor -%}
|
||||
{% endfor %}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
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)
|
||||
}
|
||||
|
||||
type ListXInterface interface {
|
||||
KeyBaseInterface
|
||||
LSet(*proto.SetRequest) ([]string, error)
|
||||
}
|
|
@ -1,76 +1,38 @@
|
|||
// Code generated by gen-struct. DO NOT EDIT.
|
||||
// Code generated by gen-struct-const. DO NOT EDIT.
|
||||
// make gen-struct generated
|
||||
|
||||
package generate
|
||||
|
||||
const (
|
||||
DEFAULT_KEY = iota
|
||||
|
||||
STRING_X
|
||||
|
||||
LIST_X
|
||||
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_COMM = iota
|
||||
|
||||
SET
|
||||
|
||||
SET
|
||||
GET
|
||||
|
||||
ADD
|
||||
|
||||
REDUCE
|
||||
|
||||
SETBIT
|
||||
|
||||
GETBIT
|
||||
|
||||
L_SET
|
||||
|
||||
)
|
||||
|
||||
var CommKeyString = map[string]int {
|
||||
|
||||
|
||||
"set": 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,
|
||||
|
||||
|
||||
|
||||
"l_set": LIST_X,
|
||||
|
||||
|
||||
}
|
||||
|
||||
var CommKey = map[int]int {
|
||||
|
||||
|
||||
SET: 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,
|
||||
|
||||
|
||||
|
||||
L_SET: LIST_X,
|
||||
|
||||
|
||||
}
|
|
@ -2,10 +2,6 @@ package structure
|
|||
|
||||
import "gitee.com/timedb/wheatCache/pkg/proto"
|
||||
|
||||
type CacheValue interface {
|
||||
LengthByte() int64
|
||||
}
|
||||
|
||||
type KeyBaseInterface interface {
|
||||
SizeByte() int64
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ def set_structure_const_template(conf: dict):
|
|||
|
||||
template = Template(tem_text)
|
||||
text = template.render(keys=keys, key_maps=key_map, sets=val_set)
|
||||
text.replace("\n\n", "\n")
|
||||
|
||||
temp_path = f"{tempPath}/structure.gen.go"
|
||||
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||
|
@ -66,19 +65,21 @@ def set_structure_const_template(conf: dict):
|
|||
|
||||
|
||||
def set_structure_interface(conf):
|
||||
print(conf)
|
||||
|
||||
# class KeyInterFace
|
||||
|
||||
with open(f"{structurePath}/interface.go") as fp:
|
||||
interfaceText = fp.read()
|
||||
|
||||
for key, item in conf.items():
|
||||
interfaceKey = "".join([k.capitalize() for k in key.split('_')])
|
||||
interfaceTitle = "type "
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf, cfg_camel = load_conf()
|
||||
set_structure_const_template(conf)
|
||||
set_structure_interface(conf)
|
||||
# set_structure_const_template(conf)
|
||||
# set_structure_interface(conf)
|
||||
set_structure_interface(cfg_camel)
|
||||
|
|
Loading…
Reference in New Issue