From ad0cdedba9f3c18380ec367ce6c6a28d7026c314 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Tue, 28 Sep 2021 22:42:11 +0800 Subject: [PATCH] feat(conf): update const conf --- conf/wheat-cache.yaml | 2 +- pkg/structure/generate/const.template | 4 +- pkg/structure/generate/interface.template | 2 +- pkg/structure/generate/storage.template | 83 ++++++++++++++++------- pkg/structure/generate/tem.yaml | 1 + 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/conf/wheat-cache.yaml b/conf/wheat-cache.yaml index 1b51a1d..f204eb2 100644 --- a/conf/wheat-cache.yaml +++ b/conf/wheat-cache.yaml @@ -5,4 +5,4 @@ env: 'dev' storage: host: '127.0.0.1' port: 5890 - + timeOut: 2 # second diff --git a/pkg/structure/generate/const.template b/pkg/structure/generate/const.template index fdedc49..cebfbf1 100644 --- a/pkg/structure/generate/const.template +++ b/pkg/structure/generate/const.template @@ -1,7 +1,7 @@ -// Code generated by gen-struct-const. DO NOT EDIT. +// Code generated by gen-struct. DO NOT EDIT. // make gen-struct generated -package generate +package structure const ( DEFAULT_KEY = iota diff --git a/pkg/structure/generate/interface.template b/pkg/structure/generate/interface.template index ebc12dc..d82ada6 100644 --- a/pkg/structure/generate/interface.template +++ b/pkg/structure/generate/interface.template @@ -1,4 +1,4 @@ -// Code generated by gen-struct-const. DO NOT EDIT. +// Code generated by gen-struct. DO NOT EDIT. // make gen-struct generated package structure diff --git a/pkg/structure/generate/storage.template b/pkg/structure/generate/storage.template index b9c6d7a..55a6096 100644 --- a/pkg/structure/generate/storage.template +++ b/pkg/structure/generate/storage.template @@ -1,45 +1,78 @@ -// TODO 添加 storage server 模板 +// 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" + + {% for name in mod_name %} + "gitee.com/timedb/wheatCache/pkg/structure/{{name}}" + {% endfor %} + + "time" ) -type server struct { +type serverSingle struct { + middleProduce event.ProduceInterface + lruProduce event.ProduceInterface + ttl time.Duration } func NewServer() proto.CommServerServer { - ser := &server{} + ser := &serverSingle{} return ser } -func (s *server) Get( +// 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.GetRequest, -) (*proto.CommendResponse, error) { - panic("implement me") -} + req *proto.{{ fun }}Request, +) (*proto.{{ fun }}Response, error) { + lruEvent := event.NewEvent("lru event") + lruEvent.InitWaitEvent() -func (s *server) Set( - ctx context.Context, - req *proto.SetRequest, -) (*proto.CommendResponse, error) { - panic("implement me") -} + 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 -func (s *server) Add(ctx context.Context, request *proto.AddRequest) (*proto.CommendResponse, error) { - panic("implement me") -} + default: + return nil, errorx.New("value err") + } -func (s *server) Reduce(ctx context.Context, request *proto.ReduceRequest) (*proto.CommendResponse, error) { - panic("implement me") -} + }) -func (s *server) Setbit(ctx context.Context, request *proto.SetbitRequest) (*proto.CommendResponse, error) { - panic("implement me") -} + lruEvent.SetValue("lru work", work) + s.lruProduce.Call(cxt, lruEvent) + resp, err := lruEvent.StartWaitEvent(s.ttl) + if err != nil { + return nil, err + } -func (s *server) Getbit(ctx context.Context, request *proto.GetbitRequest) (*proto.CommendResponse, error) { - panic("implement me") + switch resp.(type) { + case *proto.{{ fun }}Response: + default: + return nil, errorx.New("value err") + } + return resp.(*proto.{{ fun }}Response), nil } +{% endfor %} + +{% endfor %} diff --git a/pkg/structure/generate/tem.yaml b/pkg/structure/generate/tem.yaml index 9aae05e..2798f70 100644 --- a/pkg/structure/generate/tem.yaml +++ b/pkg/structure/generate/tem.yaml @@ -1,4 +1,5 @@ # 这里定义结构体的支持的命令, 以后也许会添加结构体的命令验证 +# 定义结构体名称以及方法使, 方法全部小写,结构体名称全部大写且结构体名称需要加上 _X, 如 LIST_X STRING_X: - set