-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrequest.go
56 lines (46 loc) · 1.27 KB
/
request.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
package grpc
import (
"github.com/gojek/fiber"
"github.com/gojek/fiber/protocol"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
)
type Request struct {
// Metadata will hold the grpc headers for request
Metadata metadata.MD
Message []byte
Proto proto.Message
}
func NewRequest(metadata metadata.MD, msg []byte, protoMsg proto.Message) *Request {
return &Request{
Metadata: metadata,
Message: msg,
Proto: protoMsg,
}
}
func (r *Request) Protocol() protocol.Protocol {
return protocol.GRPC
}
func (r *Request) Payload() []byte {
return r.Message
}
func (r *Request) Header() map[string][]string {
return r.Metadata
}
func (r *Request) Clone() (fiber.Request, error) {
// for grpc, we'll just return itself (no cloning)
return r, nil
}
// OperationName is naming used in tracing interceptors
func (r *Request) OperationName() string {
// For grpc implementation, serviceMethod and endpoint is init with dispatcher
return "grpc"
}
// Transform is use by backend component within a Proxy to abstract endpoint from dispatcher
func (r *Request) Transform(_ fiber.Backend) (fiber.Request, error) {
// For grpc implementation, endpoint is init with dispatcher
return r, nil
}
func (r *Request) ProtoMessage() proto.Message {
return r.Proto
}