diff --git a/pkg/structure/generate/structure.gen.go b/pkg/structure/const.gen.go similarity index 86% rename from pkg/structure/generate/structure.gen.go rename to pkg/structure/const.gen.go index e9dc9d5..fa802ac 100644 --- a/pkg/structure/generate/structure.gen.go +++ b/pkg/structure/const.gen.go @@ -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/interface.gen.go b/pkg/structure/interface.gen.go index e09faba..6aa2437 100644 --- a/pkg/structure/interface.gen.go +++ b/pkg/structure/interface.gen.go @@ -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/storage/server/server.go b/storage/server/server.go deleted file mode 100644 index 82806c3..0000000 --- a/storage/server/server.go +++ /dev/null @@ -1,44 +0,0 @@ -package server - -import ( - context "context" - "gitee.com/timedb/wheatCache/pkg/proto" -) - -type server struct { -} - -func NewServer() proto.CommServerServer { - ser := &server{} - return ser -} - -func (s *server) Get( - cxt context.Context, - req *proto.GetRequest, -) (*proto.CommendResponse, error) { - panic("implement me") -} - -func (s *server) Set( - ctx context.Context, - req *proto.SetRequest, -) (*proto.CommendResponse, error) { - panic("implement me") -} - -func (s *server) Add(ctx context.Context, request *proto.AddRequest) (*proto.CommendResponse, error) { - panic("implement me") -} - -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") -} - -func (s *server) Getbit(ctx context.Context, request *proto.GetbitRequest) (*proto.CommendResponse, error) { - panic("implement me") -} diff --git a/storage/server/single.gen.go b/storage/server/single.gen.go new file mode 100644 index 0000000..851ab87 --- /dev/null +++ b/storage/server/single.gen.go @@ -0,0 +1,260 @@ +// 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" + + "gitee.com/timedb/wheatCache/pkg/structure/stringx" + + "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() +} + +func (s *serverSingle) Set( + cxt context.Context, + req *proto.SetRequest, +) (*proto.SetResponse, error) { + lruEvent := event.NewEvent("lru event") + lruEvent.InitWaitEvent() + + work := event.EventWorkFunc(func() (interface{}, error) { + value := mockLruValue() // TODO 替换为从 lru 获取 + switch value.(type) { + case structure.StringXInterface: + resp, err := value.(structure.StringXInterface).Set(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.SetResponse: + default: + return nil, errorx.New("value err") + } + return resp.(*proto.SetResponse), nil +} + +func (s *serverSingle) Get( + cxt context.Context, + req *proto.GetRequest, +) (*proto.GetResponse, error) { + lruEvent := event.NewEvent("lru event") + lruEvent.InitWaitEvent() + + work := event.EventWorkFunc(func() (interface{}, error) { + value := mockLruValue() // TODO 替换为从 lru 获取 + switch value.(type) { + case structure.StringXInterface: + resp, err := value.(structure.StringXInterface).Get(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.GetResponse: + default: + return nil, errorx.New("value err") + } + return resp.(*proto.GetResponse), nil +} + +func (s *serverSingle) Add( + cxt context.Context, + req *proto.AddRequest, +) (*proto.AddResponse, error) { + lruEvent := event.NewEvent("lru event") + lruEvent.InitWaitEvent() + + work := event.EventWorkFunc(func() (interface{}, error) { + value := mockLruValue() // TODO 替换为从 lru 获取 + switch value.(type) { + case structure.StringXInterface: + resp, err := value.(structure.StringXInterface).Add(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.AddResponse: + default: + return nil, errorx.New("value err") + } + return resp.(*proto.AddResponse), nil +} + +func (s *serverSingle) Reduce( + cxt context.Context, + req *proto.ReduceRequest, +) (*proto.ReduceResponse, error) { + lruEvent := event.NewEvent("lru event") + lruEvent.InitWaitEvent() + + work := event.EventWorkFunc(func() (interface{}, error) { + value := mockLruValue() // TODO 替换为从 lru 获取 + switch value.(type) { + case structure.StringXInterface: + resp, err := value.(structure.StringXInterface).Reduce(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.ReduceResponse: + default: + return nil, errorx.New("value err") + } + return resp.(*proto.ReduceResponse), nil +} + +func (s *serverSingle) Setbit( + cxt context.Context, + req *proto.SetbitRequest, +) (*proto.SetbitResponse, error) { + lruEvent := event.NewEvent("lru event") + lruEvent.InitWaitEvent() + + work := event.EventWorkFunc(func() (interface{}, error) { + value := mockLruValue() // TODO 替换为从 lru 获取 + switch value.(type) { + case structure.StringXInterface: + resp, err := value.(structure.StringXInterface).Setbit(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.SetbitResponse: + default: + return nil, errorx.New("value err") + } + return resp.(*proto.SetbitResponse), nil +} + +func (s *serverSingle) Getbit( + cxt context.Context, + req *proto.GetbitRequest, +) (*proto.GetbitResponse, error) { + lruEvent := event.NewEvent("lru event") + lruEvent.InitWaitEvent() + + work := event.EventWorkFunc(func() (interface{}, error) { + value := mockLruValue() // TODO 替换为从 lru 获取 + switch value.(type) { + case structure.StringXInterface: + resp, err := value.(structure.StringXInterface).Getbit(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.GetbitResponse: + default: + return nil, errorx.New("value err") + } + return resp.(*proto.GetbitResponse), nil +}