gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/server/rpc_request.go (about) 1 package server 2 3 import ( 4 "bytes" 5 6 "gitee.com/liuxuezhan/go-micro-v1.18.0/codec" 7 "gitee.com/liuxuezhan/go-micro-v1.18.0/transport" 8 "gitee.com/liuxuezhan/go-micro-v1.18.0/util/buf" 9 ) 10 11 type rpcRequest struct { 12 service string 13 method string 14 endpoint string 15 contentType string 16 socket transport.Socket 17 codec codec.Codec 18 header map[string]string 19 body []byte 20 rawBody interface{} 21 stream bool 22 first bool 23 } 24 25 type rpcMessage struct { 26 topic string 27 contentType string 28 payload interface{} 29 header map[string]string 30 body []byte 31 codec codec.NewCodec 32 } 33 34 func (r *rpcRequest) Codec() codec.Reader { 35 return r.codec 36 } 37 38 func (r *rpcRequest) ContentType() string { 39 return r.contentType 40 } 41 42 func (r *rpcRequest) Service() string { 43 return r.service 44 } 45 46 func (r *rpcRequest) Method() string { 47 return r.method 48 } 49 50 func (r *rpcRequest) Endpoint() string { 51 return r.endpoint 52 } 53 54 func (r *rpcRequest) Header() map[string]string { 55 return r.header 56 } 57 58 func (r *rpcRequest) Body() interface{} { 59 return r.rawBody 60 } 61 62 func (r *rpcRequest) Read() ([]byte, error) { 63 // got a body 64 if r.first { 65 b := r.body 66 r.first = false 67 return b, nil 68 } 69 70 var msg transport.Message 71 err := r.socket.Recv(&msg) 72 if err != nil { 73 return nil, err 74 } 75 r.header = msg.Header 76 77 return msg.Body, nil 78 } 79 80 func (r *rpcRequest) Stream() bool { 81 return r.stream 82 } 83 84 func (r *rpcMessage) ContentType() string { 85 return r.contentType 86 } 87 88 func (r *rpcMessage) Topic() string { 89 return r.topic 90 } 91 92 func (r *rpcMessage) Payload() interface{} { 93 return r.payload 94 } 95 96 func (r *rpcMessage) Header() map[string]string { 97 return r.header 98 } 99 100 func (r *rpcMessage) Body() []byte { 101 return r.body 102 } 103 104 func (r *rpcMessage) Codec() codec.Reader { 105 b := buf.New(bytes.NewBuffer(r.body)) 106 return r.codec(b) 107 }