/
server.go
63 lines (50 loc) · 1.29 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package alloc
import (
"context"
pb "github.com/cestlascorpion/sardine/proto"
"github.com/cestlascorpion/sardine/utils"
log "github.com/sirupsen/logrus"
)
type Server struct {
*pb.UnimplementedAllocServer
impl *Alloc
}
func NewAllocServer(ctx context.Context, conf *utils.Config) (*Server, error) {
if conf == nil || !conf.Check() {
log.Errorf("invalid config")
return nil, utils.ErrInvalidParameter
}
a, err := NewAlloc(ctx, conf)
if err != nil {
log.Errorf("new alloc impl err %+v", err)
return nil, err
}
return &Server{
impl: a,
}, nil
}
func (a *Server) GenUserSeq(ctx context.Context, in *pb.GenUserSeqReq) (*pb.GenUserSeqResp, error) {
out := &pb.GenUserSeqResp{}
log.Debugf("GenUserSeq in %+v", in)
seq, err := a.impl.GenUserSeq(ctx, in.Id, in.Tag)
if err != nil {
log.Errorf("impl GenUserSeq err %+v", err)
return out, err
}
out.Id = seq
return out, nil
}
func (a *Server) GetUserSeq(ctx context.Context, in *pb.GetUserSeqReq) (*pb.GetUserSeqResp, error) {
out := &pb.GetUserSeqResp{}
log.Debugf("GetUserSeq in %+v", in)
seq, err := a.impl.GetUserSeq(ctx, in.Id, in.Tag)
if err != nil {
log.Errorf("impl GetUserSeq err %+v", err)
return out, err
}
out.Id = seq
return out, nil
}
func (a *Server) Close(ctx context.Context) error {
return a.impl.Close(ctx)
}