forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 6
/
eventhandler.go
47 lines (38 loc) · 1023 Bytes
/
eventhandler.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
package internal
import (
"io"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/jhump/protoreflect/desc"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
type EventHandler struct {
Status *status.Status
writer io.Writer
marshaler jsonpb.Marshaler
}
func NewEventHandler(writer io.Writer, resolver jsonpb.AnyResolver) *EventHandler {
return &EventHandler{
writer: writer,
marshaler: jsonpb.Marshaler{
EmitDefaults: true,
AnyResolver: resolver,
},
}
}
func (h *EventHandler) OnReceiveResponse(message proto.Message) {
if err := h.marshaler.Marshal(h.writer, message); err != nil {
logx.Error(err)
}
}
func (h *EventHandler) OnReceiveTrailers(status *status.Status, _ metadata.MD) {
h.Status = status
}
func (h *EventHandler) OnResolveMethod(_ *desc.MethodDescriptor) {
}
func (h *EventHandler) OnSendHeaders(_ metadata.MD) {
}
func (h *EventHandler) OnReceiveHeaders(_ metadata.MD) {
}