feat(shell): add recover aof
This commit is contained in:
parent
be528cbb6d
commit
4ca09febb4
|
@ -144,10 +144,21 @@ def gen_aof(proto):
|
|||
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
|
||||
# 生成 AOF 恢复机制
|
||||
tem_text = load_template("dao_aof.template")
|
||||
template = Template(tem_text)
|
||||
|
||||
text = template.render(keys=proto)
|
||||
|
||||
temp_path = f"{daoPath}/dao.gen.go"
|
||||
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
|
||||
def format_code_go():
|
||||
go_fmt(f"{daoPath}/interface.gen.go")
|
||||
go_fmt(f"{servicePath}/single_service.gen.go")
|
||||
go_fmt(f"{aofPath}/codec.gen.go")
|
||||
go_fmt(f"{daoPath}/dao.gen.go")
|
||||
|
||||
def main():
|
||||
# 加载 protobuf
|
||||
|
|
|
@ -3,10 +3,14 @@
|
|||
|
||||
package dao
|
||||
|
||||
import "gitee.com/wheat-os/wheatCache/pkg/proto"
|
||||
import (
|
||||
"gitee.com/wheat-os/wheatCache/pkg/proto"
|
||||
protobuf "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
{%for key in keys %}
|
||||
{{key.method}}({% for req in key.option %} {{req[1]}}, {% endfor %}) (*proto.{{key.method}}Response, error)
|
||||
{%- endfor %}
|
||||
ExecMessage(message protobuf.Message) error
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Code generated by gen-struct. DO NOT EDIT.
|
||||
// make gen-service generated
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gitee.com/wheat-os/wheatCache/pkg/errorx"
|
||||
"gitee.com/wheat-os/wheatCache/pkg/lru"
|
||||
"gitee.com/wheat-os/wheatCache/pkg/proto"
|
||||
protobuf "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type Dao struct {
|
||||
lru lru.CacheInterface
|
||||
}
|
||||
|
||||
func NewDao(lru lru.CacheInterface) Interface {
|
||||
return &Dao{
|
||||
lru: lru,
|
||||
}
|
||||
}
|
||||
|
||||
// 执行 msg
|
||||
func (d *Dao) ExecMessage(message protobuf.Message) error {
|
||||
switch req := message.(type) {
|
||||
{%for key in keys %}
|
||||
case *proto.{{key.method}}Request:
|
||||
_, err := d.{{key.method}}({% for req in key.option %} req.{{req[0]}}, {% endfor %})
|
||||
return err
|
||||
{%- endfor %}
|
||||
default:
|
||||
return errorx.New("The type that is not registered exec err")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue