micro-server-grpc/response.go
Vasiliy Tolstov 36040a5765 codec rewrite
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-11-26 01:17:21 +03:00

36 lines
596 B
Go

package grpc
import (
"io"
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/metadata"
)
type rpcResponse struct {
rw io.ReadWriter
header metadata.Metadata
codec codec.Codec
endpoint string
service string
method string
target string
}
func (r *rpcResponse) Codec() codec.Codec {
return r.codec
}
func (r *rpcResponse) WriteHeader(hdr metadata.Metadata) {
for k, v := range hdr {
r.header[k] = v
}
}
func (r *rpcResponse) Write(b []byte) error {
return r.codec.Write(r.rw, &codec.Message{
Header: r.header,
Body: b,
}, nil)
}