-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatcher.go
41 lines (32 loc) · 999 Bytes
/
dispatcher.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
package grpc
import (
"context"
"errors"
"github.com/jasonsoft/log"
deliveryNats "github.com/jasonsoft/wakanda/pkg/dispatcher/delivery/nats"
deliveryProto "github.com/jasonsoft/wakanda/pkg/dispatcher/proto"
)
var (
_emptyDispatcherCommandReply = deliveryProto.DispatcherCommandReply{}
)
type DispatcherServer struct {
dispatcherPub *deliveryNats.DispatcherPub
}
func NewDispatcherServer(nats *deliveryNats.DispatcherPub) *DispatcherServer {
return &DispatcherServer{
dispatcherPub: nats,
}
}
func (svc *DispatcherServer) HandleCommand(ctx context.Context, in *deliveryProto.DispatcherCommandRequest) (*deliveryProto.DispatcherCommandReply, error) {
log.Debugf("dispatcher: receiver op: %s", in.OP)
switch in.OP {
case "MSGRM":
return svc.handleMSGRM(ctx, in)
case "LOGIN":
return svc.handleTOKEN(ctx, in)
default:
log.Warnf("dispatcher: unknown command: %s", in.OP)
reply := &deliveryProto.DispatcherCommandReply{}
return reply, errors.New("unknown command")
}
}