feat(shell): update shell storage

This commit is contained in:
bandl 2021-10-04 20:07:06 +08:00
parent 7c6c26c5fa
commit c27328ced4
2 changed files with 2 additions and 76 deletions

View File

@ -1,74 +0,0 @@
// Code generated by gen-struct. DO NOT EDIT.
// make gen-struct generated
package server
import (
context "context"
"gitee.com/timedb/wheatCache/pkg/errorx"
"gitee.com/timedb/wheatCache/pkg/event"
"gitee.com/timedb/wheatCache/pkg/proto"
"gitee.com/timedb/wheatCache/pkg/structure"
"time"
)
type serverSingle struct {
middleProduce event.ProduceInterface
lruProduce event.ProduceInterface
ttl time.Duration
}
func NewServer() proto.CommServerServer {
ser := &serverSingle{}
return ser
}
// TODO 移除
func mockLruValue() structure.KeyBaseInterface {
return stringx.NewStringSingle()
}
{% for opt in option %}
{% for fun in opt.option %}
func (s *serverSingle) {{ fun }} (
cxt context.Context,
req *proto.{{ fun }}Request,
) (*proto.{{ fun }}Response, error) {
lruEvent := event.NewEvent("lru event")
lruEvent.InitWaitEvent()
work := event.EventWorkFunc(func() (interface{}, error) {
value := mockLruValue() // TODO 替换为从 lru 获取
switch value.(type) {
case structure.{{ opt.key }}Interface:
resp, err := value.(structure.{{ opt.key }}Interface).{{ fun }}(req)
if err != nil {
return nil, err
}
return resp, nil
default:
return nil, errorx.New("value err")
}
})
lruEvent.SetValue("lru work", work)
s.lruProduce.Call(cxt, lruEvent)
resp, err := lruEvent.StartWaitEvent(s.ttl)
if err != nil {
return nil, err
}
switch resp.(type) {
case *proto.{{ fun }}Response:
default:
return nil, errorx.New("value err")
}
return resp.(*proto.{{ fun }}Response), nil
}
{% endfor %}
{% endfor %}

View File

@ -113,7 +113,7 @@ def format_code_go():
if __name__ == "__main__": if __name__ == "__main__":
conf, cfg_camel = load_conf() conf, cfg_camel = load_conf()
set_structure_const_template(conf) set_structure_const_template(conf)
set_structure_interface(cfg_camel) # set_structure_interface(cfg_camel)
set_storage_server(cfg_camel) # set_storage_server(cfg_camel)
# 格式化代码 # 格式化代码
format_code_go() format_code_go()