micro-server-grpc/request.go

101 lines
1.6 KiB
Go
Raw Permalink Normal View History

2019-06-03 20:44:43 +03:00
package grpc
import (
"io"
"go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v3/server"
)
var (
_ server.Request = &rpcRequest{}
_ server.Message = &rpcMessage{}
2019-06-03 20:44:43 +03:00
)
type rpcRequest struct {
rw io.ReadWriter
payload interface{}
codec codec.Codec
header metadata.Metadata
2019-06-03 20:44:43 +03:00
method string
endpoint string
2019-06-03 20:44:43 +03:00
contentType string
service string
2019-06-03 20:44:43 +03:00
body []byte
stream bool
}
type rpcMessage struct {
payload interface{}
codec codec.Codec
header metadata.Metadata
topic string
contentType string
body []byte
2019-06-03 20:44:43 +03:00
}
func (r *rpcRequest) ContentType() string {
return r.contentType
}
func (r *rpcRequest) Service() string {
return r.service
}
func (r *rpcRequest) Method() string {
return r.method
}
func (r *rpcRequest) Endpoint() string {
return r.endpoint
2019-06-03 20:44:43 +03:00
}
func (r *rpcRequest) Codec() codec.Codec {
2019-06-03 20:44:43 +03:00
return r.codec
}
func (r *rpcRequest) Header() metadata.Metadata {
2019-06-03 20:44:43 +03:00
return r.header
}
func (r *rpcRequest) Read() ([]byte, error) {
f := &codec.Frame{}
if err := r.codec.ReadBody(r.rw, f); err != nil {
2019-06-18 20:51:52 +03:00
return nil, err
}
return f.Data, nil
2019-06-03 20:44:43 +03:00
}
func (r *rpcRequest) Stream() bool {
return r.stream
}
func (r *rpcRequest) Body() interface{} {
return r.payload
}
func (r *rpcMessage) ContentType() string {
return r.contentType
}
func (r *rpcMessage) Topic() string {
return r.topic
}
func (r *rpcMessage) Payload() interface{} {
return r.payload
}
func (r *rpcMessage) Header() metadata.Metadata {
return r.header
}
func (r *rpcMessage) Body() []byte {
return r.body
}
func (r *rpcMessage) Codec() codec.Codec {
return r.codec
}