gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/server/grpc/request.go (about) 1 package grpc 2 3 import ( 4 "gitee.com/liuxuezhan/go-micro-v1.18.0/codec" 5 "gitee.com/liuxuezhan/go-micro-v1.18.0/codec/bytes" 6 ) 7 8 type rpcRequest struct { 9 service string 10 method string 11 contentType string 12 codec codec.Codec 13 header map[string]string 14 body []byte 15 stream bool 16 payload interface{} 17 } 18 19 type rpcMessage struct { 20 topic string 21 contentType string 22 payload interface{} 23 header map[string]string 24 body []byte 25 codec codec.Codec 26 } 27 28 func (r *rpcRequest) ContentType() string { 29 return r.contentType 30 } 31 32 func (r *rpcRequest) Service() string { 33 return r.service 34 } 35 36 func (r *rpcRequest) Method() string { 37 return r.method 38 } 39 40 func (r *rpcRequest) Endpoint() string { 41 return r.method 42 } 43 44 func (r *rpcRequest) Codec() codec.Reader { 45 return r.codec 46 } 47 48 func (r *rpcRequest) Header() map[string]string { 49 return r.header 50 } 51 52 func (r *rpcRequest) Read() ([]byte, error) { 53 f := &bytes.Frame{} 54 if err := r.codec.ReadBody(f); err != nil { 55 return nil, err 56 } 57 return f.Data, nil 58 } 59 60 func (r *rpcRequest) Stream() bool { 61 return r.stream 62 } 63 64 func (r *rpcRequest) Body() interface{} { 65 return r.payload 66 } 67 68 func (r *rpcMessage) ContentType() string { 69 return r.contentType 70 } 71 72 func (r *rpcMessage) Topic() string { 73 return r.topic 74 } 75 76 func (r *rpcMessage) Payload() interface{} { 77 return r.payload 78 } 79 80 func (r *rpcMessage) Header() map[string]string { 81 return r.header 82 } 83 84 func (r *rpcMessage) Body() []byte { 85 return r.body 86 } 87 88 func (r *rpcMessage) Codec() codec.Reader { 89 return r.codec 90 }