forked from p93542168/wheat-cache
feat(shell): update shell storage
This commit is contained in:
parent
7c6c26c5fa
commit
c27328ced4
|
@ -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 %}
|
|
@ -113,7 +113,7 @@ def format_code_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_interface(cfg_camel)
|
||||
# set_storage_server(cfg_camel)
|
||||
# 格式化代码
|
||||
format_code_go()
|
||||
|
|
Loading…
Reference in New Issue