github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/server/grpc/request.go (about) 1 // Copyright 2020 Asim Aslam 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Original source: github.com/micro/go-micro/v3/server/grpc/request.go 16 17 package grpc 18 19 import ( 20 "github.com/tickoalcantara12/micro/v3/util/codec" 21 "github.com/tickoalcantara12/micro/v3/util/codec/bytes" 22 ) 23 24 type rpcRequest struct { 25 service string 26 method string 27 contentType string 28 codec codec.Codec 29 header map[string]string 30 body []byte 31 stream bool 32 payload interface{} 33 } 34 35 type rpcMessage struct { 36 topic string 37 contentType string 38 payload interface{} 39 header map[string]string 40 body []byte 41 codec codec.Codec 42 } 43 44 func (r *rpcRequest) ContentType() string { 45 return r.contentType 46 } 47 48 func (r *rpcRequest) Service() string { 49 return r.service 50 } 51 52 func (r *rpcRequest) Method() string { 53 return r.method 54 } 55 56 func (r *rpcRequest) Endpoint() string { 57 return r.method 58 } 59 60 func (r *rpcRequest) Codec() codec.Reader { 61 return r.codec 62 } 63 64 func (r *rpcRequest) Header() map[string]string { 65 return r.header 66 } 67 68 func (r *rpcRequest) Read() ([]byte, error) { 69 f := &bytes.Frame{} 70 if err := r.codec.ReadBody(f); err != nil { 71 return nil, err 72 } 73 return f.Data, nil 74 } 75 76 func (r *rpcRequest) Stream() bool { 77 return r.stream 78 } 79 80 func (r *rpcRequest) Body() interface{} { 81 return r.payload 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 return r.codec 106 }