diff --git a/makefile b/makefile index 6380d3c..1932289 100644 --- a/makefile +++ b/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 diff --git a/pkg/structure/generate/const.template b/pkg/structure/generate/const.template index 8fa6f67..fdedc49 100644 --- a/pkg/structure/generate/const.template +++ b/pkg/structure/generate/const.template @@ -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 %} } \ No newline at end of file diff --git a/pkg/structure/generate/inteerface.template b/pkg/structure/generate/inteerface.template new file mode 100644 index 0000000..1b08892 --- /dev/null +++ b/pkg/structure/generate/inteerface.template @@ -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) +} diff --git a/pkg/structure/generate/structure.gen.go b/pkg/structure/generate/structure.gen.go index d9c8589..9931336 100644 --- a/pkg/structure/generate/structure.gen.go +++ b/pkg/structure/generate/structure.gen.go @@ -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, - - } \ No newline at end of file diff --git a/pkg/structure/interface.go b/pkg/structure/interface.go index 1e69347..61d498f 100644 --- a/pkg/structure/interface.go +++ b/pkg/structure/interface.go @@ -2,10 +2,6 @@ package structure import "gitee.com/timedb/wheatCache/pkg/proto" -type CacheValue interface { - LengthByte() int64 -} - type KeyBaseInterface interface { SizeByte() int64 diff --git a/shell/make-struct.py b/shell/make-struct.py index b03c8b2..bd06602 100644 --- a/shell/make-struct.py +++ b/shell/make-struct.py @@ -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)