chore(structure): update structure
This commit is contained in:
parent
187280bc2c
commit
600ecb644e
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue